-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimage_process.py
More file actions
39 lines (30 loc) · 1.37 KB
/
image_process.py
File metadata and controls
39 lines (30 loc) · 1.37 KB
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
import cv2
import global_values
class Images:
def __init__(self,frame):
self.image= frame
cv2.namedWindow("Test")
def get_contours(self,image):
imgray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(imgray, (3, 3), 0)
ret,thresh = cv2.threshold(blurred,50,255,cv2.THRESH_BINARY + cv2.THRESH_OTSU)
contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.imshow('Test',thresh)
return contours
def only_red(self):
frame=self.image
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_red_mask = cv2.inRange(hsv, global_values.lower_red1, global_values.upper_red1)
upper_red_mask = cv2.inRange(hsv, global_values.lower_red2, global_values.upper_red2)
mask = lower_red_mask + upper_red_mask
return cv2.bitwise_and(frame,frame, mask= mask)
def only_blue(self):
frame=self.image
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, global_values.lower_blue, global_values.upper_blue)
return cv2.bitwise_and(frame,frame, mask= mask)
def only_green(self):
frame=self.image
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, global_values.lower_green, global_values.upper_green)
return cv2.bitwise_and(frame,frame, mask= mask)