forked from team3997/ChickenVision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
range_detector.py
69 lines (48 loc) · 1.87 KB
/
range_detector.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# import the necessary packages
import numpy as np
import imutils
import cv2
minHVal = 0
minSVal = 0
minVVal = 0
maxHVal = 255
maxSVal = 255
maxVVal = 255
def callback(value):
pass
cv2.namedWindow("Trackbars", 0)
cv2.createTrackbar('H (min)', "Trackbars", minHVal, 255, callback)
cv2.createTrackbar('S (min)', "Trackbars", minSVal, 255, callback)
cv2.createTrackbar('V (min)', "Trackbars", minVVal, 255, callback)
cv2.createTrackbar('H (max)', "Trackbars", maxHVal, 255, callback)
cv2.createTrackbar('S (max)', "Trackbars", maxSVal, 255, callback)
cv2.createTrackbar('V (max)', "Trackbars", maxVVal, 255, callback)
camera = cv2.VideoCapture('http://10.0.66.12:1181/stream.mjpg')
while True:
minHVal = cv2.getTrackbarPos('H (min)', "Trackbars")
minSVal = cv2.getTrackbarPos('S (min)', "Trackbars")
minVVal = cv2.getTrackbarPos('V (min)', "Trackbars")
maxHVal = cv2.getTrackbarPos('H (max)', "Trackbars")
maxSVal = cv2.getTrackbarPos('S (max)', "Trackbars")
maxVVal = cv2.getTrackbarPos('V (max)', "Trackbars")
(grabbed, frame) = camera.read()
height = frame.shape[0]
width = frame.shape[1]
#resize the frame
frame = imutils.resize(frame, width=600)
#convert to HSV color space
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
#construct a mask for the color, then perform
#a series of dilations and erosions to remove any small
#blobs left in the mask
mask = cv2.inRange(hsv, (minHVal, minSVal, minVVal), (maxHVal, maxSVal, maxVVal))
mask = cv2.erode(mask, None, iterations=2)
mask = cv2.dilate(mask, None, iterations=2)
cv2.imshow("Frame", frame)
cv2.imshow("Mask", mask)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
# cleanup the camera and close open windows
camera.release()
cv2.destroyAllWindows()