-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontours.py
More file actions
30 lines (18 loc) · 740 Bytes
/
Copy pathcontours.py
File metadata and controls
30 lines (18 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import cv2 as cv
import numpy as np
img = cv.imread('Photos/cat6.jpg')
cv.imshow('Cats', img)
blank = np.zeros(img.shape, dtype='uint8')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow('Gray', gray)
blur = cv.GaussianBlur(gray, (5,5), cv.BORDER_DEFAULT)
cv.imshow('Blur', blur)
canny = cv.Canny(img,125,175)
cv.imshow('Canny Edges', canny)
ret, thresh = cv.threshold(gray, 175,255, cv.THRESH_BINARY)
cv.imshow('Thresh', thresh)
contours, hierarchies = cv.findContours(canny ,cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE) # Contours -> list of cordinates of contours, Hierarchies -> shapes
print(f'{len(contours)} contour(s) found')
cv.drawContours(blank, contours, -1, (0,0,255), 1)
cv.imshow('Contours Drawn', blank)
cv.waitKey(0)