-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #917 from jakaskerl/main
Adding code examples in docs
- Loading branch information
Showing
12 changed files
with
764 additions
and
4 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,62 @@ | ||
UVC | ||
=== | ||
|
||
The DepthAI UVC (`USB Video Class <https://en.wikipedia.org/wiki/USB_video_device_class>`__) node allows OAK devices to function as standard webcams. This feature is particularly useful for integrating OAK devices into applications that require video input, such as video conferencing tools or custom video processing applications. | ||
|
||
What is UVC? | ||
############ | ||
|
||
UVC refers to the USB Video Class standard, which is a USB device class that describes devices capable of streaming video. This standard allows video devices to interface with computers and other devices without needing specific drivers, making them immediately compatible with a wide range of systems and software. | ||
|
||
How Does the UVC Node Work? | ||
########################### | ||
|
||
The UVC node in DepthAI leverages this standard to stream video from OAK devices. When the UVC node is enabled, the OAK device is recognized as a standard webcam by the host system. This allows the device to be used in any application that supports webcam input, such as Zoom, Skype, or custom video processing software. | ||
|
||
The UVC node streams video data over a USB connection. It is important to use a USB3 cable for this purpose, as USB2 may not provide the necessary bandwidth for stable video streaming. | ||
|
||
.. note:: | ||
|
||
The UVC node can currently handle NV12 video streams from OAK devices. For streams in other formats, conversion to NV12 is necessary, which can be achieved using the :ref:`ImageManip` node. It's important to note that streams incompatible with NV12 conversion, like depth streams, are not supported by the UVC node. | ||
|
||
Examples of UVC Node Usage | ||
########################## | ||
|
||
1. **DepthAI Demo Script**: The DepthAI demo script includes a UVC application that can be run to enable the UVC node on an OAK device. | ||
|
||
.. code-block:: bash | ||
python3 depthai_demo.py --app uvc | ||
2. **Custom Python Script**: A custom Python script can be written to enable the UVC node and configure the video stream parameters. Here are some pre-written examples: | ||
|
||
- :ref:`UVC & Color Camera` | ||
- :ref:`UVC & Mono Camera` | ||
- :ref:`UVC & Disparity` | ||
|
||
|
||
3. **OBS Forwarding**: For applications where direct UVC node usage is not possible, OBS Studio can be used to forward the UVC stream. | ||
|
||
|
||
Reference | ||
######### | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Python | ||
|
||
.. autoclass:: depthai.node.UVC | ||
:members: | ||
:inherited-members: | ||
:noindex: | ||
|
||
.. tab:: C++ | ||
|
||
.. doxygenclass:: dai::node::UVC | ||
:project: depthai-core | ||
:members: | ||
:private-members: | ||
:undoc-members: | ||
|
||
|
||
.. include:: ../../includes/footer-short.rst |
37 changes: 37 additions & 0 deletions
37
docs/source/samples/FeatureTracker/feature_motion_estimation.rst
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,37 @@ | ||
Feature Tracker with Motion Estimation | ||
====================================== | ||
|
||
This example demonstrates the capabilities of the :ref:`FeatureTracker` combined with motion estimation. It detects and tracks features between consecutive frames using optical flow. | ||
Each feature is assigned a unique ID. The motion of the camera is estimated based on the tracked features, and the estimated motion (e.g., Up, Down, Left, Right, Rotating) is displayed on screen. | ||
|
||
The :ref:`Feature Detector` example only detects features without estimating motion. | ||
|
||
Demo | ||
#### | ||
|
||
.. image:: ../../../../docs/source/_static/images/examples/feature_motion_estimation.gif | ||
:alt: Feature Tracker with Motion Estimation Demo | ||
:width: 100% | ||
:align: center | ||
|
||
|
||
Setup | ||
##### | ||
|
||
.. include:: /includes/install_from_pypi.rst | ||
|
||
Source code | ||
########### | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Python | ||
|
||
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/FeatureTracker/feature_motion_estimation.py>`__ | ||
|
||
.. literalinclude:: ../../../../examples/FeatureTracker/feature_motion_estimation.py | ||
:language: python | ||
:linenos: | ||
|
||
|
||
.. include:: /includes/footer-short.rst |
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,70 @@ | ||
UVC & Disparity | ||
=============== | ||
|
||
This example demonstrates how to use your OAK device as a UVC webcam. The UVC feature allows you to use your OAK device as a regular webcam in applications like OpenCV's :code:`cv2.VideoCapture()`, native camera apps, and more. | ||
|
||
.. rubric:: How It Works: | ||
|
||
The :ref:`StereoDepth` node outputs image data in the UINT8 format. However, the :ref:`UVC` node expects the data in NV12 format. To bridge this gap, an intermediary :ref:`ImageManip` node is used to convert the GRAY8 output from the MonoCamera node to NV12 format, which is then passed to the UVC node for streaming. | ||
This doesn't work with stereo depth output, since depth is UINT16 which we cannot convert to NV12. | ||
|
||
This example won't work if we enable the subpixel disparity feature, since that outputs UINT16 as well. | ||
|
||
.. rubric:: Similar samples: | ||
|
||
- :ref:`UVC & Color Camera` | ||
- :ref:`UVC & Mono Camera` | ||
|
||
|
||
Setup | ||
##### | ||
|
||
.. include:: /includes/install_from_pypi.rst | ||
|
||
Code used for testing | ||
##################### | ||
|
||
.. code-block:: python | ||
import cv2 | ||
# Initialize the VideoCapture object to use the default camera (camera index 0 is webcam) | ||
cap = cv2.VideoCapture(1) | ||
# Check if the camera opened successfully | ||
if not cap.isOpened(): | ||
print("Error: Could not open camera.") | ||
exit() | ||
# Loop to continuously get frames from the camera | ||
while True: | ||
ret, frame = cap.read() | ||
if not ret: | ||
print("Error: Could not read frame.") | ||
break | ||
cv2.imshow('Video Feed', frame) | ||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
cap.release() | ||
cv2.destroyAllWindows() | ||
Source code | ||
########### | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Python | ||
|
||
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/UVC/uvc_disparity.py>`__ | ||
|
||
.. literalinclude:: ../../../../examples/UVC/uvc_disparity.py | ||
:language: python | ||
:linenos: | ||
|
||
|
||
.. include:: /includes/footer-short.rst |
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,69 @@ | ||
UVC & Mono Camera | ||
================= | ||
|
||
This example demonstrates how to use a mono camera on your OAK device to function as a webcam. The UVC feature allows you to use your OAK device as a regular webcam in applications like OpenCV's :code:`cv2.VideoCapture()`, native camera apps, and more. | ||
|
||
.. rubric:: How It Works: | ||
|
||
The :ref:`MonoCamera` node outputs image data in the GRAY8 format. However, the :ref:`UVC` node expects the data in NV12 format. To bridge this gap, an intermediary :ref:`ImageManip` node is used to convert the GRAY8 output from the MonoCamera node to NV12 format, which is then passed to the UVC node for streaming. | ||
|
||
|
||
.. rubric:: Similar samples: | ||
|
||
- :ref:`UVC & Color Camera` | ||
- :ref:`UVC & Disparity` | ||
|
||
|
||
Setup | ||
##### | ||
|
||
.. include:: /includes/install_from_pypi.rst | ||
|
||
Code used for testing | ||
##################### | ||
|
||
.. code-block:: python | ||
import cv2 | ||
# Initialize the VideoCapture object to use the default camera (camera index 0 is webcam) | ||
cap = cv2.VideoCapture(1) | ||
# Check if the camera opened successfully | ||
if not cap.isOpened(): | ||
print("Error: Could not open camera.") | ||
exit() | ||
# Loop to continuously get frames from the camera | ||
while True: | ||
ret, frame = cap.read() | ||
if not ret: | ||
print("Error: Could not read frame.") | ||
break | ||
cv2.imshow('Video Feed', frame) | ||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
cap.release() | ||
cv2.destroyAllWindows() | ||
Source code | ||
########### | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Python | ||
|
||
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/UVC/uvc_mono.py>`__ | ||
|
||
.. literalinclude:: ../../../../examples/UVC/uvc_mono.py | ||
:language: python | ||
:linenos: | ||
|
||
|
||
.. include:: /includes/footer-short.rst |
Oops, something went wrong.