-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorphological transfromations .py
47 lines (35 loc) · 1.23 KB
/
morphological transfromations .py
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
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 18 19:45:16 2018
@author: dpr
"""
import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while(1):
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_red = np.array([30,150,50])
upper_red = np.array([255,255,180])
mask = cv2.inRange(hsv, lower_red, upper_red)
res = cv2.bitwise_and(frame,frame, mask= mask)
# It is the difference between input image and Opening of the image
#cv2.imshow('Tophat',tophat)
# It is the difference between the closing of the input image and input image.
#cv2.imshow('Blackhat',blackhat)
kernel = np.ones((2,2),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(opening, cv2.MORPH_CLOSE, kernel)
cv2.imshow('Original',frame)
cv2.imshow('Mask',mask)
cv2.imshow('Opening',opening)
cv2.imshow('closing',closing)
#cv2.imshow('Erosion',erosion)
#cv2.imshow('Dilation',dilation)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
cap.release()