-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add minor bug fixes - Add example 03 for multithreading - Improve overall performance - Update and improve documentation
- Loading branch information
Showing
20 changed files
with
189 additions
and
100 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,15 @@ | ||
Example 03: Detect and track objects in multithreading | ||
====================================================== | ||
|
||
- **Description:** Use VSense to detect and track objects in a video in multithreading. | ||
- **Featuring:** | ||
- :py:class:`VSense` | :py:class:`vsensebox.vsense.vsense.VSense` | ||
- :py:func:`draw_boxes` | :py:func:`vsensebox.utils.visualizetools.draw_boxes` | ||
|
||
ℹ️ **Source code and input file(s)** -> `{vsensebox repo}/examples`_ | ||
|
||
.. _{vsensebox repo}/examples: https://github.com/rathaumons/vsensebox/tree/main/examples | ||
|
||
.. literalinclude:: ../../examples/example_03.py | ||
:encoding: latin-1 | ||
|
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,3 @@ | ||
tracker: Centroid | ||
max_spread: 48 | ||
pref_y: Top # Top/Center/Bottom |
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,66 @@ | ||
# Example 03: Detect and track objects in multithreading | ||
|
||
import cv2 | ||
import threading | ||
from vsensebox import VSense | ||
from vsensebox.utils.visualizetools import draw_boxes | ||
|
||
|
||
def detect_and_track(vsense, input_video, det_yaml, trk_yaml, name="Detect & Track"): | ||
|
||
# Read video | ||
cap = cv2.VideoCapture(input_video) | ||
|
||
# Loop each frame | ||
while cap.isOpened(): | ||
|
||
hasFrame, frame = cap.read() | ||
if hasFrame: | ||
|
||
# Detect object using local YAML config | ||
vsense.detect(img=frame, | ||
config_yaml=det_yaml, | ||
img_is_mat=True) | ||
|
||
# Track object using local YAML config | ||
vsense.track(img=frame, | ||
config_yaml=trk_yaml, | ||
img_is_mat=True) | ||
|
||
# Draw bounding boxes of the detected objects | ||
frame = draw_boxes( | ||
frame, ids=vsense.assets.ids, | ||
boxes_xyxy=vsense.assets.boxes_xyxy, | ||
boxes_confs=vsense.assets.boxes_confs | ||
) | ||
|
||
# Display | ||
cv2.imshow("VSenseBox: Example 03 - " + name, frame) | ||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
else: | ||
break | ||
|
||
cap.release() | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
vs1 = VSense() | ||
vs2 = VSense() | ||
|
||
vs1_thread = threading.Thread( | ||
target=detect_and_track, | ||
args=(vs1, "gta.mp4", "yolo_ultralytics_v8n.yaml", "sort.yaml", "VSense 1") | ||
) | ||
|
||
vs2_thread = threading.Thread( | ||
target=detect_and_track, | ||
args=(vs2, "gta.mp4", "yolo_ultralytics_v8n.yaml", "centroid.yaml", "VSense 2") | ||
) | ||
|
||
vs1_thread.start() | ||
vs2_thread.start() | ||
vs1_thread.join() | ||
vs2_thread.join() | ||
|
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
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
Binary file not shown.
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
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
Oops, something went wrong.