This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import the required libraries | |
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#read the image | |
image = cv2.imread('coins.jpg') | |
#calculate the edges using Canny edge algorithm | |
edges = cv2.Canny(image,100,200) | |
#plot the edges |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing the required libraries | |
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
image = cv2.imread('index.png') | |
#using the averaging kernel for image smoothening | |
averaging_kernel = np.ones((3,3),np.float32)/9 | |
filtered_image = cv2.filter2D(image,-1,kernel) | |
plt.imshow(dst) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing the required libraries | |
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
image = cv2.imread('shapes.png') | |
#converting RGB image to Binary | |
gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) | |
ret,thresh = cv2.threshold(gray_image,127,255,0) | |
#calculate the contours from binary image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import required libraries | |
import cv2 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#show OpenCV version | |
print(cv2.__version__) | |
#read the iamge and convert to grayscale | |
image = cv2.imread('index.png') | |
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import required libraries | |
import cv2 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#show OpenCV version | |
print(cv2.__version__) | |
#read image and convert to grayscale | |
image = cv2.imread('index.png') | |
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#reading images in grayscale format | |
image1 = cv2.imread('messi.jpg',0) | |
image2 = cv2.imread('team.jpg',0) | |
#finding out the keypoints and their descriptors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import required libraries | |
import numpy as np | |
import cv2 as cv | |
import matplotlib.pyplot as plt | |
%matplotlib inline | |
#load the classifiers downloaded | |
face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') | |
eye_cascade = cv.CascadeClassifier('haarcascade_eye.xml') | |
#read the image and convert to grayscale format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#importing required modules | |
from keras.applications import VGG16 | |
#loading the saved model | |
#we are using the complete architecture thus include_top=True | |
model = VGG16(weights='imagenet',include_top=True) | |
#show the summary of model | |
model.summary() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#creating a mapping of layer name ot layer details | |
#we will create a dictionary layers_info which maps a layer name to its charcteristics | |
layers_info = {} | |
for i in model.layers: | |
layers_info[i.name] = i.get_config() | |
#here the layer_weights dictionary will map every layer_name to its corresponding weights | |
layer_weights = {} | |
for i in model.layers: | |
layer_weights[i.name] = i.get_weights() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
layers = model.layers | |
layer_ids = [1,4,7,11,15] | |
#plot the filters | |
fig,ax = plt.subplots(nrows=1,ncols=5) | |
for i in range(5): | |
ax[i].imshow(layers[layer_ids[i]].get_weights()[0][:,:,:,0][:,:,0],cmap='gray') | |
ax[i].set_title('block'+str(i+1)) | |
ax[i].set_xticks([]) | |
ax[i].set_yticks([]) |