For the OAK-D S2, we are using the pre-made rgb_preview.cpp example (except we changed the resolution output):
#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(1920, 1080);
camRgb->setBoardSocket(dai::CameraBoardSocket::CAM_A);
camRgb->setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
camRgb->setInterleaved(false);
camRgb->setColorOrder(dai::ColorCameraProperties::ColorOrder::RGB);
camRgb->setFps(30); // Set FPS to 30
// 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;
}
For the OAK 4D, we are using the premade camera_output.cpp exampe:
#include <iostream>
#include <memory>
#include <opencv2/opencv.hpp>
#include "depthai/depthai.hpp"
#include <chrono>
int main() {
// Create device
std::shared_ptr<dai::Device> device = std::make_shared<dai::Device>();
// Create pipeline
dai::Pipeline pipeline(device);
// Create nodes
auto cam = pipeline.create<dai::node::Camera>()->build();
//auto videoQueue = cam->requestOutput(std::make_pair(640, 400))->createOutputQueue();
std::cout << "FPS: " << cam->getMaxRequestedFps() << std::endl;
auto videoQueue = cam->requestOutput(std::make_pair(1920, 1080))->createOutputQueue();
videoQueue->setBlocking(false);
videoQueue->setMaxSize(1);
// Start pipeline
pipeline.start();
while(true) {
auto videoIn = videoQueue->get<dai::ImgFrame>();
if(videoIn == nullptr) continue;
cv::imshow("video", videoIn->getCvFrame());
if(cv::waitKey(1) == 'q') {
break;
}
}
return 0;
}