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

Histograms – OpenCV 3.4 with python 3 Tutorial 11

Source code: import cv2 import numpy as np from matplotlib import pyplot as plt img = cv2.imread("sea_beach.jpg") b, g, r = cv2.split(img) cv2.imshow("img", img) cv2.imshow("b", b) cv2.imshow("g", g) cv2.imshow("r", r) plt.hist(b.ravel(), 256, [0, 256]) plt.hist(g.ravel(), 256, [0, 256]) plt.hist(r.ravel(), 256, [0, 256]) plt.show() Files: sea.jpg…

Basic Thresholding – OpenCV 3.4 with python 3 Tutorial 10

Threshold: import cv2 import numpy as np img = cv2.imread("black_to_white.jpeg", cv2.IMREAD_GRAYSCALE) _, threshold_binary = cv2.threshold(img, 128, 255, cv2.THRESH_BINARY) _, threshold_binary_inv = cv2.threshold(img, 128, 255, cv2.THRESH_BINARY_INV) _, threshold_trunc = cv2.threshold(img, 128, 255, cv2.THRESH_TRUNC) _, threshold_to_zero = cv2.threshold(img, 12, 255, cv2.THRESH_TOZERO) cv2.imshow("Image", img) cv2.imshow("th binary", threshold_binary) cv2.imshow("th…

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