I am currently using the OAK-1 with a YOLOv8 Nano network, which runs smoothly at around 60 inference FPS. However, the camera stream is quite laggy, and I've seen other models perform better in video streams. Is it possible to optimize my code? Currently, I'm getting about 15 FPS from the camera stream.
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include "depthai/depthai.hpp"
int main() {
std::string nnPath("PATH");
dai::Pipeline pipeline;
*auto* camera = pipeline.create<dai::node::ColorCamera>();
*auto* network = pipeline.create<dai::node::YoloDetectionNetwork>();
*auto* cameraOutput = pipeline.create<dai::node::XLinkOut>();
*auto* networkOutput = pipeline.create<dai::node::XLinkOut>();
cameraOutput**->**setStreamName("rgb");
networkOutput**->**setStreamName("detections");
camera**->**setPreviewSize(640, 640);
camera**->**setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
camera**->**setInterleaved(*false*);
camera**->**setColorOrder(dai::ColorCameraProperties::ColorOrder::BGR);
network**->**setConfidenceThreshold(0.5f);
network**->**setNumClasses(1);
network**->**setCoordinateSize(4);
network**->**setIouThreshold(0.5f);
network**->**setBlobPath(nnPath);
network**->**setNumInferenceThreads(2);
network**->**input.setBlocking(*false*);
camera**->**preview.link(network**->**input);
camera**->**preview.link(cameraOutput**->**input);
network**->**out.link(networkOutput**->**input);
dai::Device device(pipeline);
*auto* cameraQueue = device.getOutputQueue("rgb", 8, *false*);
*auto* networkQueue = device.getOutputQueue("detections", 8, *false*);
*while*(*true*) {
cv::Mat frame;
std::vector<dai::ImgDetection> detections;
std::shared_ptr<dai::ImgFrame> cameraInput;
std::shared_ptr<dai::ImgDetections> networkInput;
cameraInput **=** cameraQueue**->**tryGet<dai::ImgFrame>();
networkInput **=** networkQueue**->**tryGet<dai::ImgDetections>();
*if*(cameraInput) {
frame **=** cameraInput**->**getCvFrame();
}
*if*(networkInput) {
*auto* color = cv::Scalar(255, 0, 0);
detections **=** networkInput**->**detections;
*for* (*const auto*& detection : detections) {
std::cout **<<** "Label: " **<<** detection.label
**<<** ", Confidence: " **<<** detection.confidence
**<<** ", Bounding Box: [" **<<** detection.xmin **<<** ", " **<<** detection.ymin **<<** ", " **<<** detection.xmax **<<** ", " **<<** detection.ymax **<<** "]"
**<<** std::endl;
}
}
*if*(!frame.empty()) {
cv::imshow("oak", frame);
}
*if* (cv::waitKey(1) == 27) {
*break*;
}
}
*return* 0;
}