Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2.cv2 as cv2
- img = cv2.imread("E:\Photos_for_TZ\gordon.jpg")
- img1 = cv2.imread("E:\Photos_for_TZ\gordon.jpg", 0)
- ret, thresh = cv2.threshold(img1, 170, 255, cv2.THRESH_BINARY)
- contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
- print('Число контуров функции threshold:' + str(len(contours)))
- blur = cv2.GaussianBlur(img1,(1,1), cv2.BORDER_DEFAULT)
- canny = cv2.Canny(image = blur, threshold1 = 170, threshold2 = 230, apertureSize = 3, L2gradient = True)
- contours1, hierarchy = cv2.findContours(canny, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
- print('Число контуров функции Canny:'+ str(len(contours1)) +'\n')
- cv2.drawContours(img, contours1, -1, (30, 170, 230), 2)
- cv2.imshow('Original', img)
- cv2.imshow('Grayscale', img1)
- cv2.imshow('Threshold', thresh)
- cv2.imshow('Canny', canny)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement