-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec414fd
commit f46a22f
Showing
3 changed files
with
111 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# author: Arun Ponnusamy | ||
# website: https://www.arunponnusamy.com | ||
|
||
# object detection video example using tiny yolo model. | ||
# usage: python object_detection_video_yolov3_tiny.py /path/to/video | ||
|
||
# import necessary packages | ||
import cvlib as cv | ||
from cvlib.object_detection import draw_bbox | ||
import cv2 | ||
import sys | ||
|
||
# open webcam | ||
video = cv2.VideoCapture(sys.argv[1]) | ||
|
||
if not video.isOpened(): | ||
print("Could not open video") | ||
exit() | ||
|
||
|
||
# loop through frames | ||
while video.isOpened(): | ||
|
||
# read frame from webcam | ||
status, frame = video.read() | ||
|
||
if not status: | ||
break | ||
|
||
# apply object detection | ||
bbox, label, conf = cv.detect_common_objects(frame, confidence=0.25, model='yolov3-tiny') | ||
|
||
print(bbox, label, conf) | ||
|
||
# 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 | ||
video.release() | ||
cv2.destroyAllWindows() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# author: Arun Ponnusamy | ||
# website: https://www.arunponnusamy.com | ||
|
||
# object detection webcam example using tiny yolo | ||
# usage: python object_detection_webcam_yolov3_tiny.py | ||
|
||
# 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, confidence=0.25, model='yolov3-tiny') | ||
|
||
print(bbox, label, conf) | ||
|
||
# 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() |