RGB Preview¶
This example shows how to set up a pipeline that outputs a small preview of the RGB camera, connects over XLink to transfer these to the host real-time, and displays the RGB frames on the host with OpenCV.
Note that preview frames are not suited for larger resolution (eg. 1920x1080). Preview is more suitable for either NN or visualization purposes. Please check out ColorCamera node to get a better view.
If you want to get higher resolution RGB frames sample please visit RGB video.
Similar samples:
RGB video (higher resolution)
Demo¶
Setup¶
Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai-python repository first and then run the script
git clone https://github.com/luxonis/depthai-python.git
cd depthai-python/examples
python3 install_requirements.py
For additional information, please follow installation guide
Source code¶
Also available on GitHub
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 | #!/usr/bin/env python3
import cv2
import depthai as dai
# Create pipeline
pipeline = dai.Pipeline()
# Define source and output
camRgb = pipeline.create(dai.node.ColorCamera)
xoutRgb = pipeline.create(dai.node.XLinkOut)
xoutRgb.setStreamName("rgb")
# Properties
camRgb.setPreviewSize(300, 300)
camRgb.setInterleaved(False)
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
# Linking
camRgb.preview.link(xoutRgb.input)
# Connect to device and start pipeline
with dai.Device(pipeline) as device:
print('Connected cameras:', device.getConnectedCameraFeatures())
# Print out usb speed
print('Usb speed:', device.getUsbSpeed().name)
# Bootloader version
if device.getBootloaderVersion() is not None:
print('Bootloader version:', device.getBootloaderVersion())
# Device name
print('Device name:', device.getDeviceName(), ' Product name:', device.getProductName())
# Output queue will be used to get the rgb frames from the output defined above
qRgb = device.getOutputQueue(name="rgb", maxSize=4, blocking=False)
while True:
inRgb = qRgb.get() # blocking call, will wait until a new data has arrived
# Retrieve 'bgr' (opencv format) frame
cv2.imshow("rgb", inRgb.getCvFrame())
if cv2.waitKey(1) == ord('q'):
break
|
Also available on GitHub
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 | #include <iostream>
// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"
int main() {
using namespace std;
// Create pipeline
dai::Pipeline pipeline;
// Define source and output
auto camRgb = pipeline.create<dai::node::ColorCamera>();
auto xoutRgb = pipeline.create<dai::node::XLinkOut>();
xoutRgb->setStreamName("rgb");
// Properties
camRgb->setPreviewSize(300, 300);
camRgb->setBoardSocket(dai::CameraBoardSocket::CAM_A);
camRgb->setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
camRgb->setInterleaved(false);
camRgb->setColorOrder(dai::ColorCameraProperties::ColorOrder::RGB);
// Linking
camRgb->preview.link(xoutRgb->input);
// Connect to device and start pipeline
dai::Device device(pipeline, dai::UsbSpeed::SUPER);
cout << "Connected cameras: " << device.getConnectedCameraFeatures() << endl;
// Print USB speed
cout << "Usb speed: " << device.getUsbSpeed() << endl;
// Bootloader version
if(device.getBootloaderVersion()) {
cout << "Bootloader version: " << device.getBootloaderVersion()->toString() << endl;
}
// Device name
cout << "Device name: " << device.getDeviceName() << " Product name: " << device.getProductName() << endl;
// Output queue will be used to get the rgb frames from the output defined above
auto qRgb = device.getOutputQueue("rgb", 4, false);
while(true) {
auto inRgb = qRgb->get<dai::ImgFrame>();
// Retrieve 'bgr' (opencv format) frame
cv::imshow("rgb", inRgb->getCvFrame());
int key = cv::waitKey(1);
if(key == 'q' || key == 'Q') {
break;
}
}
return 0;
}
|