10 static const std::vector<std::string>
labelMap = {
"background",
"aeroplane",
"bicycle",
"bird",
"boat",
"bottle",
"bus",
11 "car",
"cat",
"chair",
"cow",
"diningtable",
"dog",
"horse",
12 "motorbike",
"person",
"pottedplant",
"sheep",
"sofa",
"train",
"tvmonitor"};
14 int main(
int argc,
char** argv) {
16 using namespace std::chrono;
19 std::string nnPath(BLOB_PATH);
20 std::string videoPath(VIDEO_PATH);
24 nnPath = std::string(argv[1]);
25 videoPath = std::string(argv[2]);
29 printf(
"Using blob at path: %s\n", nnPath.c_str());
30 printf(
"Using video at path: %s\n", videoPath.c_str());
41 xinFrame->setStreamName(
"inFrame");
45 nn->setConfidenceThreshold(0.5);
46 nn->setBlobPath(nnPath);
47 nn->setNumInferenceThreads(2);
48 nn->input.setBlocking(
false);
51 xinFrame->out.link(nn->input);
52 nn->out.link(nnOut->input);
63 auto displayFrame = [](std::string name, cv::Mat frame, std::vector<dai::ImgDetection>& detections) {
64 auto color = cv::Scalar(255, 0, 0);
66 for(
auto& detection : detections) {
67 int x1 = detection.xmin * frame.cols;
68 int y1 = detection.ymin * frame.rows;
69 int x2 = detection.xmax * frame.cols;
70 int y2 = detection.ymax * frame.rows;
72 uint32_t labelIndex = detection.label;
73 std::string labelStr =
to_string(labelIndex);
77 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
78 std::stringstream confStr;
79 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
80 cv::putText(frame, confStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
81 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
84 cv::imshow(name, frame);
88 cv::VideoCapture cap(videoPath);
90 cv::namedWindow(
"inFrame", cv::WINDOW_NORMAL);
91 cv::resizeWindow(
"inFrame", 1280, 720);
92 std::cout <<
"Resize video window with mouse drag!" << std::endl;
94 while(cap.isOpened()) {
97 if(frame.empty())
break;
99 auto img = std::make_shared<dai::ImgFrame>();
102 img->setTimestamp(steady_clock::now());
110 displayFrame(
"inFrame", frame, detections);
112 int key = cv::waitKey(1);
113 if(key ==
'q' || key ==
'Q')
return 0;