-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblur&smooth.py
37 lines (29 loc) · 959 Bytes
/
blur&smooth.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
import cv2
import numpy as np
cap=cv2.VideoCapture(0)
while True :
_, frame = cap.read()
hsv =cv2.cvtColor(frame,cv2.COLOR_BGR2HSV) #hue saturation value
lower_red=np.array([50,0,0])
upper_red=np.array([255,255,255])
"""dark_red=np.uintB([[[12,22,121]]])
dark_red=cv2.cvtColor(dark_red,cv2.COLOR_BGR2HSV)"""
mask = cv2.inRange(hsv,lower_red,upper_red)
res=cv2.bitwise_and(frame,frame,mask=mask)
kernel =np.ones((15,15),np.float32)/225
smoothed=cv2.filter2D(res,-1,kernel)
blur=cv2.GaussianBlur(res ,(15,15),0)
median = cv2.medianBlur(res,15)
bilateral =cv2.bilateralFilter(res,15,75,75)
cv2.imshow('frame',frame)
#cv2.imshow('mask',mask)
cv2.imshow('res',res)
cv2.imshow('blur',blur)
cv2.imshow('median',median)
cv2.imshow('bilateral',bilateral)
#cv2.imshow('smoothed',smoothed)
k=cv2.waitKey(0)
if k==27:
break
cv2.destroyAllWindows()
cap.release()