Corners detection – OpenCV 3.4 with python 3 Tutorial 22

Corners detection image: [python] 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() [/python]   Corners detection Video real time: [python] import […]

Template matching – OpenCV 3.4 with python 3 Tutorial 20

Template matching image: [python] 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] + h), (0, 255, 0), 3) cv2.imshow("img", img) cv2.waitKey(0) cv2.destroyAllWindows() […]

Find and Draw Contours – OpenCV 3.4 with python 3 Tutorial 19

We’re going to see in this tutorial how to find and draw the contours. Contours are simply the boundaries of an object. We first import the libraries and we load the Camera. import cv2 import numpy as np cap = cv2.VideoCapture(0) We start the while loop to work with a video, so we loop trough […]

Edge detection – OpenCV 3.4 with python 3 Tutorial 18

What you will learn about edge detection The opencv edge detection is the image processing procedure, that allows you to structure the image pixels in order to show and highlight their edges. With opencv this operation can be done with three methods: -Sobel edge detection-Laplacian edge detection-Canny edge detection What is the best method for […]

Morphological transformation – OpenCV 3.4 with python 3 Tutorial 17

Source code Images transformation: [python] import cv2 import numpy as np img = cv2.imread("balls.jpg", cv2.IMREAD_GRAYSCALE) _, mask = cv2.threshold(img, 250, 255, cv2.THRESH_BINARY_INV) kernel = np.ones((5, 5), np.uint8) dilation = cv2.dilate(mask, kernel) erosion = cv2.erode(mask, kernel, iterations=6) cv2.imshow("Image", img) cv2.imshow("Mask", mask) cv2.imshow("Dilation", dilation) cv2.imshow("Erosion", erosion) cv2.waitKey(0) cv2.destroyAllWindows() [/python]   Real Time Video Morphological transformation: [python] import […]

Smoothing images – OpenCV 3.4 with python 3 Tutorial 16

[python] import cv2 import numpy as np img = cv2.imread("early_1800.jpg") averaging = cv2.blur(img, (21, 21)) gaussian = cv2.GaussianBlur(img, (21, 21), 0) median = cv2.medianBlur(img, 5) bilateral = cv2.bilateralFilter(img, 9, 350, 350) cv2.imshow("Original image", img) cv2.imshow("Averaging", averaging) cv2.imshow("Gaussian", gaussian) cv2.imshow("Median", median) cv2.imshow("Bilateral", bilateral) cv2.waitKey(0) cv2.destroyAllWindows() [/python]   Files: early_1800.jpg balloons_noisy.png carpet.jpg lake.jpg

Adaptive thresholding – OpenCV 3.4 with python 3 Tutorial 15

[python] import cv2 import numpy as np img = cv2.imread("book_page.jpg") _, threshold = cv2.threshold(img, 155, 255, cv2.THRESH_BINARY) img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) mean_c = cv2.adaptiveThreshold(img_gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 15, 12) gaus = cv2.adaptiveThreshold(img_gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 91, 12) cv2.imshow("Img", img) cv2.imshow("Binary threshold", threshold) cv2.imshow("Mean C", mean_c) cv2.imshow("Gaussian", gaus) cv2.waitKey(0) cv2.destroyAllWindows() [/python]   Files: book_page.jpg

Affine transformation – OpenCV 3.4 with python 3 Tutorial 14

[python] import cv2 import numpy as np img = cv2.imread("grid.jpg") rows, cols, ch = img.shape cv2.circle(img, (83, 90), 5, (0, 0, 255), -1) cv2.circle(img, (447, 90), 5, (0, 0, 255), -1) cv2.circle(img, (83, 472), 5, (0, 0, 255), -1) pts1 = np.float32([[83, 90], [447, 90], [83, 472]]) pts2 = np.float32([[0, 0], [447, 90], [150, 472]]) […]