7 static const std::vector<std::string>
labelMap = {
"background",
"aeroplane",
"bicycle",
"bird",
"boat",
"bottle",
"bus",
8 "car",
"cat",
"chair",
"cow",
"diningtable",
"dog",
"horse",
9 "motorbike",
"person",
"pottedplant",
"sheep",
"sofa",
"train",
"tvmonitor"};
11 int main(
int argc,
char** argv) {
15 std::string nnPath(BLOB_PATH);
19 nnPath = std::string(argv[1]);
23 printf(
"Using blob at path: %s\n", nnPath.c_str());
36 xoutVideo->setStreamName(
"video");
41 camRgb->setPreviewSize(300, 300);
43 camRgb->setInterleaved(
false);
44 camRgb->setPreviewKeepAspectRatio(
false);
46 nn->setConfidenceThreshold(0.5);
47 nn->setBlobPath(nnPath);
48 nn->setNumInferenceThreads(2);
49 nn->input.setBlocking(
false);
53 camRgb->preview.link(xoutPreview->
input);
54 camRgb->preview.link(nn->input);
55 nn->out.link(nnOut->
input);
67 std::vector<dai::ImgDetection> detections;
70 auto displayFrame = [](std::string name, cv::Mat frame, std::vector<dai::ImgDetection>& detections) {
71 auto color = cv::Scalar(255, 0, 0);
73 for(
auto& detection : detections) {
74 int x1 = detection.xmin * frame.cols;
75 int y1 = detection.ymin * frame.rows;
76 int x2 = detection.xmax * frame.cols;
77 int y2 = detection.ymax * frame.rows;
79 uint32_t labelIndex = detection.label;
80 std::string labelStr =
to_string(labelIndex);
84 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
85 std::stringstream confStr;
86 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
87 cv::putText(frame, confStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
88 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
91 cv::imshow(name, frame);
94 cv::namedWindow(
"video", cv::WINDOW_NORMAL);
95 cv::resizeWindow(
"video", 1280, 720);
96 cout <<
"Resize video window with mouse drag!" << endl;
105 videoFrame = inVideo->getCvFrame();
113 detections = inDet->detections;
116 if(!videoFrame.empty()) {
117 displayFrame(
"video", videoFrame, detections);
120 if(!previewFrame.empty()) {
121 displayFrame(
"preview", previewFrame, detections);
124 int key = cv::waitKey(1);
125 if(key ==
'q' || key ==
'Q') {