opencvlib.py
881 Bytes
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
# import necessary packages
import cvlib as cv
from cvlib.object_detection import draw_bbox
import cv2
# open webcam (웹캠 열기)
webcam = cv2.VideoCapture(0)
if not webcam.isOpened():
print("Could not open webcam")
exit()
# loop through frames
while webcam.isOpened():
# read frame from webcam
status, frame = webcam.read()
if not status:
break
# apply object detection (물체 검출)
bbox, label, conf = cv.detect_common_objects(frame)
# draw bounding box over detected objects (검출된 물체 가장자리에 바운딩 박스 그리기)
out = draw_bbox(frame, bbox, label, conf, write_conf=True)
# display output
cv2.imshow("Real-time object detection", out)
# press "Q" to stop
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# release resources
webcam.release()
cv2.destroyAllWindows()