-
Notifications
You must be signed in to change notification settings - Fork 0
/
hsv_belirleme.py
59 lines (42 loc) · 1.65 KB
/
hsv_belirleme.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
import cv2.cv2 as cv2
import numpy as np
cap = cv2.VideoCapture(0)
# trackbar icin bos fonks olusturma
def nothing(x):
pass
# trackbar penceresi olusturma
cv2.namedWindow("Trackbar")
cv2.resizeWindow("Trackbar", 500, 500)
# trackbar olusturma
cv2.createTrackbar("Lower - H", "Trackbar", 0, 180, nothing)
cv2.createTrackbar("Lower - S", "Trackbar", 0, 255, nothing)
cv2.createTrackbar("Lower - V", "Trackbar", 0, 255, nothing)
cv2.createTrackbar("Upper - H", "Trackbar", 0, 180, nothing)
cv2.createTrackbar("Upper - S", "Trackbar", 0, 255, nothing)
cv2.createTrackbar("Upper - V", "Trackbar", 0, 255, nothing)
# trackbar ustdegerlerini set etme
cv2.setTrackbarPos("Upper - H", "Trackbar", 180)
cv2.setTrackbarPos("Upper - S", "Trackbar", 255)
cv2.setTrackbarPos("Upper - V", "Trackbar", 255)
while True:
lower_h = cv2.getTrackbarPos("Lower - H", "Trackbar")
lower_s = cv2.getTrackbarPos("Lower - S", "Trackbar")
lower_v = cv2.getTrackbarPos("Lower - V", "Trackbar")
upper_h = cv2.getTrackbarPos("Upper - H", "Trackbar")
upper_s = cv2.getTrackbarPos("Upper - S", "Trackbar")
upper_v = cv2.getTrackbarPos("Upper - V", "Trackbar")
lower_color = np.array([lower_h, lower_s, lower_v])
upper_color = np.array([upper_h, upper_s, upper_v])
ret, frame = cap.read()
frame = cv2.resize(frame, (640, 480))
frame = cv2.flip(frame, 1)
hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv_frame, lower_color, upper_color)
cv2.imshow("frame", frame)
cv2.imshow("mask", mask)
if cv2.waitKey(100) & 0xFF == ord("q"):
break
if ret == False:
break
cap.release()
cv2.destroyAllWindows()