11 static const std::vector<std::string>
labelMap = {
"background",
"aeroplane",
"bicycle",
"bird",
"boat",
"bottle",
"bus",
12 "car",
"cat",
"chair",
"cow",
"diningtable",
"dog",
"horse",
13 "motorbike",
"person",
"pottedplant",
"sheep",
"sofa",
"train",
"tvmonitor"};
15 static std::atomic<bool>
syncNN{
true};
17 int main(
int argc,
char** argv) {
19 using namespace std::chrono;
22 std::string nnPath(BLOB_PATH);
26 nnPath = std::string(argv[1]);
30 printf(
"Using blob at path: %s\n", nnPath.c_str());
42 xoutRgb->setStreamName(
"rgb");
46 camRgb->setPreviewSize(300, 300);
47 camRgb->setInterleaved(
false);
50 nn->setNumInferenceThreads(2);
51 nn->input.setBlocking(
false);
57 det->setConfidenceThreshold(0.5);
61 nn->passthrough.link(xoutRgb->
input);
66 camRgb->preview.link(nn->input);
67 nn->out.link(det->
input);
78 std::vector<dai::ImgDetection> detections;
79 auto startTime = steady_clock::now();
82 auto color2 = cv::Scalar(255, 255, 255);
85 auto displayFrame = [](std::string name, cv::Mat frame, std::vector<dai::ImgDetection>& detections) {
86 auto color = cv::Scalar(255, 0, 0);
88 for(
auto& detection : detections) {
89 int x1 = detection.xmin * frame.cols;
90 int y1 = detection.ymin * frame.rows;
91 int x2 = detection.xmax * frame.cols;
92 int y2 = detection.ymax * frame.rows;
94 uint32_t labelIndex = detection.label;
95 std::string labelStr =
to_string(labelIndex);
99 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
100 std::stringstream confStr;
101 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
102 cv::putText(frame, confStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
103 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
106 cv::imshow(name, frame);
110 std::shared_ptr<dai::ImgFrame> inRgb;
111 std::shared_ptr<dai::ImgDetections> inDet;
122 auto currentTime = steady_clock::now();
123 auto elapsed = duration_cast<duration<float>>(currentTime - startTime);
124 if(elapsed > seconds(1)) {
125 fps = counter / elapsed.count();
127 startTime = currentTime;
131 frame = inRgb->getCvFrame();
132 std::stringstream fpsStr;
133 fpsStr <<
"NN fps: " << std::fixed << std::setprecision(2) <<
fps;
134 cv::putText(frame, fpsStr.str(), cv::Point(2, inRgb->getHeight() - 4), cv::FONT_HERSHEY_TRIPLEX, 0.4, color2);
138 detections = inDet->detections;
142 displayFrame(
"video", frame, detections);
145 int key = cv::waitKey(1);
146 if(key ==
'q' || key ==
'Q') {