-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhaar_find.py
34 lines (26 loc) · 1012 Bytes
/
haar_find.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
import numpy as np
import cv2
mode = "image"
# mode = "webcam"
outlet_cascade = cv2.CascadeClassifier('./classifier_usa_outlet/cascade.xml')
if mode=="image":
img = cv2.imread('test_image/test_outlet_usa.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
outlets = outlet_cascade.detectMultiScale(gray, 1.1, 2, minSize=(12,12))
for (x,y,w,h) in outlets:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
cv2.imshow('img',img)
cv2.imwrite('test_image/test_outlet_usa_result.jpg', img)
cv2.waitKey(0)
if mode=="webcam":
video_capture = cv2.VideoCapture(0)
while True:
ret, img = video_capture.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
outlets = outlet_cascade.detectMultiScale(gray, 1.2, 10, minSize=(10,10))
for (x,y,w,h) in outlets:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
cv2.imshow('img',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()