-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmorphological.py
More file actions
37 lines (27 loc) · 951 Bytes
/
morphological.py
File metadata and controls
37 lines (27 loc) · 951 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
31
32
33
34
35
36
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
#HSV hue sat value
lower_color = np.array([10,10,10])
upper_color = np.array([100,255,255])
mask = cv2.inRange(hsv, lower_color, upper_color)
res = cv2.bitwise_and(frame, frame, mask = mask)
kernel = np.ones((5,5), np.uint8)
erosion = cv2.erode(mask,kernel, iterations = 1)
dilation = cv2.dilate(mask, kernel, iterations = 1)
opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
cv2.imshow('frame', frame)
cv2.imshow('res', res)
cv2.imshow('erosion', erosion)
cv2.imshow('dilation', dilation)
cv2.imshow('closing', closing)
cv2.imshow('opening', opening)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()