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"};
13 int main(
int argc,
char** argv) {
15 using namespace std::chrono;
16 std::string nnPath(BLOB_PATH);
20 nnPath = std::string(argv[1]);
24 printf(
"Using blob at path: %s\n", nnPath.c_str());
37 xlinkOut->setStreamName(
"preview");
41 camRgb->setPreviewSize(300, 300);
43 camRgb->setInterleaved(
false);
48 detectionNetwork->setBlobPath(nnPath);
49 detectionNetwork->setConfidenceThreshold(0.5f);
50 detectionNetwork->input.setBlocking(
false);
52 objectTracker->setDetectionLabelsToTrack({15});
59 camRgb->preview.link(detectionNetwork->input);
60 objectTracker->passthroughTrackerFrame.link(xlinkOut->input);
63 camRgb->video.link(objectTracker->inputTrackerFrame);
65 detectionNetwork->passthrough.link(objectTracker->inputTrackerFrame);
68 detectionNetwork->passthrough.link(objectTracker->inputDetectionFrame);
69 detectionNetwork->out.link(objectTracker->inputDetections);
70 objectTracker->out.link(trackerOut->
input);
78 auto startTime = steady_clock::now();
87 auto currentTime = steady_clock::now();
88 auto elapsed = duration_cast<duration<float>>(currentTime - startTime);
89 if(elapsed > seconds(1)) {
90 fps = counter / elapsed.count();
92 startTime = currentTime;
95 auto color = cv::Scalar(255, 0, 0);
96 cv::Mat frame = imgFrame->getCvFrame();
97 auto trackletsData = track->tracklets;
98 for(
auto& t : trackletsData) {
99 auto roi = t.roi.denormalize(frame.cols, frame.rows);
100 int x1 = roi.topLeft().x;
101 int y1 = roi.topLeft().y;
102 int x2 = roi.bottomRight().x;
103 int y2 = roi.bottomRight().y;
105 uint32_t labelIndex = t.label;
106 std::string labelStr =
to_string(labelIndex);
110 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
112 std::stringstream idStr;
113 idStr <<
"ID: " << t.id;
114 cv::putText(frame, idStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
115 std::stringstream statusStr;
116 statusStr <<
"Status: " << t.status;
117 cv::putText(frame, statusStr.str(), cv::Point(x1 + 10, y1 + 60), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
119 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
122 std::stringstream fpsStr;
123 fpsStr <<
"NN fps:" << std::fixed << std::setprecision(2) <<
fps;
124 cv::putText(frame, fpsStr.str(), cv::Point(2, imgFrame->getHeight() - 4), cv::FONT_HERSHEY_TRIPLEX, 0.4, color);
126 cv::imshow(
"tracker", frame);
128 int key = cv::waitKey(1);
129 if(key ==
'q' || key ==
'Q') {