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)…

Morphological transformation – OpenCV 3.4 with python 3 Tutorial 17

Source code Images transformation: 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()…

Smoothing images – OpenCV 3.4 with python 3 Tutorial 16

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()   Files:…

Adaptive thresholding – OpenCV 3.4 with python 3 Tutorial 15

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",…

Copyright © Pysource 2017-2019, VAT: PL9721276174, Poznan (Poland) - Privacy Policy