Mouse Events – OpenCV 3.4 with python 3 Tutorial 27

  Draw circles: import cv2 import numpy as np def mouse_drawing(event, x, y, flags, params): if event == cv2.EVENT_LBUTTONDOWN: print("Left click") circles.append((x, y)) cap = cv2.VideoCapture(0) cv2.namedWindow("Frame") cv2.setMouseCallback("Frame", mouse_drawing) circles = [] while True: _, frame = cap.read() for center_position in circles: cv2.circle(frame, center_position, 5,…

Feature Matching (Brute-Force) – OpenCV 3.4 with python 3 Tutorial 26

Source code: import cv2 import numpy as np img1 = cv2.imread("the_book_thief.jpg", cv2.IMREAD_GRAYSCALE) img2 = cv2.imread("me_holding_book.jpg", cv2.IMREAD_GRAYSCALE) # ORB Detector orb = cv2.ORB_create() kp1, des1 = orb.detectAndCompute(img1, None) kp2, des2 = orb.detectAndCompute(img2, None) # Brute Force Matching bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) matches = bf.match(des1, des2) matches…

Image Pyramids – OpenCV 3.4 with python 3 Tutorial 23

Source code: import cv2 import numpy as np img = cv2.imread("hand.jpg") # Gaussian Pyramid layer = img.copy() gaussian_pyramid = [layer] for i in range(6): layer = cv2.pyrDown(layer) gaussian_pyramid.append(layer) # Laplacian Pyramid layer = gaussian_pyramid[5] cv2.imshow("6", layer) laplacian_pyramid = [layer] for i in range(5, 0, -1):…

Corners detection – OpenCV 3.4 with python 3 Tutorial 22

Corners detection image: import cv2 import numpy as np img = cv2.imread("squares.jpg") gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) corners = cv2.goodFeaturesToTrack(gray, 150, 0.8, 50) corners = np.int0(corners) for corner in corners: x, y = corner.ravel() cv2.circle(img, (x, y), 5, (0, 0, 255), -1) cv2.imshow("img", img) cv2.waitKey(0) cv2.destroyAllWindows()…

Template matching – OpenCV 3.4 with python 3 Tutorial 20

Template matching image: import cv2 import numpy as np img = cv2.imread("simpsons.jpg") gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) template = cv2.imread("barts_face.jpg", cv2.IMREAD_GRAYSCALE) w, h = template.shape[::-1] result = cv2.matchTemplate(gray_img, template, cv2.TM_CCOEFF_NORMED) loc = np.where(result >= 0.4) for pt in zip(*loc[::-1]): cv2.rectangle(img, pt, (pt[0] + w, pt[1] +…

Edge detection – OpenCV 3.4 with python 3 Tutorial 18

Image edge detection: import cv2 import numpy as np img = cv2.imread("white_panda.jpg", cv2.IMREAD_GRAYSCALE) img = cv2.GaussianBlur(img, (11, 11), 0) sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0) sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1) laplacian = cv2.Laplacian(img, cv2.CV_64F, ksize=5) canny = cv2.Canny(img, 100, 150) cv2.imshow("Image", img) cv2.imshow("Sobelx", sobelx)…

Copyright © Pysource LTD 2017-2019, VAT: BG205838657, Plovdiv (Bulgaria) - Privacy Policy