-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObj_Detection.py
63 lines (44 loc) · 1.27 KB
/
Obj_Detection.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
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 6 15:54:47 2020
@author: USER
"""
import cv2
font = cv2.FONT_HERSHEY_SIMPLEX
# face recognition function
def objDetect() :
obj_cascade = cv2.CascadeClassifier('cascade.xml')
# Camera Setting
cap = cv2.VideoCapture(0)
if cap.isOpened() == False:
print ('Can\'t open the CAM')
cap.set(3, 680) # set video widht
cap.set(4, 600) # set video height
print("widht: ", cap.get(3))
print("heihgt: ", cap.get(4))
count = 0
while True :
ret, frame = cap.read()
frame = cv2.flip(frame, 1)
if not ret :
break
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
objs = obj_cascade.detectMultiScale(
gray,
scaleFactor = 1.1,
minNeighbors = 5,
minSize = (100, 100)
)
# draw
for (x, y, w, h) in objs :
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
# update
cv2.imshow('Demo01', frame)
count += 1
if cv2.waitKey(1) > 0 :
break
# Destory all
cap.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
objDetect()