12 static const std::vector<std::string>
labelMap = {
13 "person",
"bicycle",
"car",
"motorbike",
"aeroplane",
"bus",
"train",
"truck",
"boat",
14 "traffic light",
"fire hydrant",
"stop sign",
"parking meter",
"bench",
"bird",
"cat",
"dog",
"horse",
15 "sheep",
"cow",
"elephant",
"bear",
"zebra",
"giraffe",
"backpack",
"umbrella",
"handbag",
16 "tie",
"suitcase",
"frisbee",
"skis",
"snowboard",
"sports ball",
"kite",
"baseball bat",
"baseball glove",
17 "skateboard",
"surfboard",
"tennis racket",
"bottle",
"wine glass",
"cup",
"fork",
"knife",
"spoon",
18 "bowl",
"banana",
"apple",
"sandwich",
"orange",
"broccoli",
"carrot",
"hot dog",
"pizza",
19 "donut",
"cake",
"chair",
"sofa",
"pottedplant",
"bed",
"diningtable",
"toilet",
"tvmonitor",
20 "laptop",
"mouse",
"remote",
"keyboard",
"cell phone",
"microwave",
"oven",
"toaster",
"sink",
21 "refrigerator",
"book",
"clock",
"vase",
"scissors",
"teddy bear",
"hair drier",
"toothbrush"};
23 static std::atomic<bool>
syncNN{
true};
25 int main(
int argc,
char** argv) {
27 using namespace std::chrono;
28 std::string nnPath(BLOB_PATH);
32 nnPath = std::string(argv[1]);
36 printf(
"Using blob at path: %s\n", nnPath.c_str());
47 xoutRgb->setStreamName(
"rgb");
51 camRgb->setPreviewSize(640, 352);
53 camRgb->setInterleaved(
false);
58 detectionNetwork->setConfidenceThreshold(0.5f);
59 detectionNetwork->setNumClasses(80);
60 detectionNetwork->setCoordinateSize(4);
61 detectionNetwork->setIouThreshold(0.5f);
62 detectionNetwork->setBlobPath(nnPath);
63 detectionNetwork->setNumInferenceThreads(2);
64 detectionNetwork->input.setBlocking(
false);
69 detectionNetwork->passthrough.link(xoutRgb->input);
74 detectionNetwork->out.link(nnOut->
input);
84 std::vector<dai::ImgDetection> detections;
85 auto startTime = steady_clock::now();
88 auto color2 = cv::Scalar(255, 255, 255);
91 auto displayFrame = [](std::string name, cv::Mat frame, std::vector<dai::ImgDetection>& detections) {
92 auto color = cv::Scalar(255, 0, 0);
94 for(
auto& detection : detections) {
95 int x1 = detection.xmin * frame.cols;
96 int y1 = detection.ymin * frame.rows;
97 int x2 = detection.xmax * frame.cols;
98 int y2 = detection.ymax * frame.rows;
100 uint32_t labelIndex = detection.label;
101 std::string labelStr =
to_string(labelIndex);
105 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, 255);
106 std::stringstream confStr;
107 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
108 cv::putText(frame, confStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, 255);
109 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
112 cv::imshow(name, frame);
116 std::shared_ptr<dai::ImgFrame> inRgb;
117 std::shared_ptr<dai::ImgDetections> inDet;
128 auto currentTime = steady_clock::now();
129 auto elapsed = duration_cast<duration<float>>(currentTime - startTime);
130 if(elapsed > seconds(1)) {
131 fps = counter / elapsed.count();
133 startTime = currentTime;
137 frame = inRgb->getCvFrame();
138 std::stringstream fpsStr;
139 fpsStr <<
"NN fps: " << std::fixed << std::setprecision(2) <<
fps;
140 cv::putText(frame, fpsStr.str(), cv::Point(2, inRgb->getHeight() - 4), cv::FONT_HERSHEY_TRIPLEX, 0.4, color2);
144 detections = inDet->detections;
148 displayFrame(
"rgb", frame, detections);
151 int key = cv::waitKey(1);
152 if(key ==
'q' || key ==
'Q') {