9 static const std::vector<std::string>
labelMap = {
"",
"person"};
13 int main(
int argc,
char** argv) {
15 using namespace std::chrono;
16 std::string nnPath(BLOB_PATH);
17 std::string videoPath(VIDEO_PATH);
21 nnPath = std::string(argv[1]);
22 videoPath = std::string(argv[2]);
26 printf(
"Using blob at path: %s\n", nnPath.c_str());
27 printf(
"Using video at path: %s\n", videoPath.c_str());
43 manipOut->setStreamName(
"manip");
50 xinFrame->setMaxDataSize(1920 * 1080 * 3);
52 manip->initialConfig.setResizeThumbnail(544, 320);
57 manip->inputImage.setBlocking(
true);
60 detectionNetwork->setBlobPath(nnPath);
61 detectionNetwork->setConfidenceThreshold(0.5);
62 detectionNetwork->input.setBlocking(
true);
64 objectTracker->inputTrackerFrame.setBlocking(
true);
65 objectTracker->inputDetectionFrame.setBlocking(
true);
66 objectTracker->inputDetections.setBlocking(
true);
67 objectTracker->setDetectionLabelsToTrack({1});
74 manip->
out.
link(manipOut->input);
75 manip->out.link(detectionNetwork->input);
76 xinFrame->out.link(manip->inputImage);
77 xinFrame->out.link(objectTracker->inputTrackerFrame);
79 detectionNetwork->
out.
link(objectTracker->inputDetections);
80 detectionNetwork->passthrough.link(objectTracker->inputDetectionFrame);
81 objectTracker->
out.
link(trackerOut->input);
82 objectTracker->passthroughTrackerFrame.link(xlinkOut->
input);
93 auto startTime = steady_clock::now();
98 std::vector<dai::ImgDetection> detections;
101 auto displayFrame = [](std::string name, cv::Mat frame, std::vector<dai::ImgDetection>& detections) {
102 auto color = cv::Scalar(255, 0, 0);
104 for(
auto& detection : detections) {
105 int x1 = detection.xmin * frame.cols;
106 int y1 = detection.ymin * frame.rows;
107 int x2 = detection.xmax * frame.cols;
108 int y2 = detection.ymax * frame.rows;
110 uint32_t labelIndex = detection.label;
111 std::string labelStr =
to_string(labelIndex);
115 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
116 std::stringstream confStr;
117 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
118 cv::putText(frame, confStr.str(), cv::Point(x1 + 10, y1 + 40), 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 cv::imshow(name, frame);
125 cv::VideoCapture cap(videoPath);
126 auto baseTs = steady_clock::now();
127 float simulatedFps = 30;
129 while(cap.isOpened()) {
132 if(frame.empty())
break;
134 auto img = std::make_shared<dai::ImgFrame>();
137 img->setTimestamp(baseTs);
138 baseTs += steady_clock::duration(
static_cast<int64_t
>((1000 * 1000 * 1000 / simulatedFps)));
140 img->setHeight(1080);
154 auto currentTime = steady_clock::now();
155 auto elapsed = duration_cast<duration<float>>(currentTime - startTime);
156 if(elapsed > seconds(1)) {
157 fps = counter / elapsed.count();
159 startTime = currentTime;
162 detections = inDet->detections;
163 manipFrame = inManip->getCvFrame();
164 displayFrame(
"nn", manipFrame, detections);
166 auto color = cv::Scalar(255, 0, 0);
167 cv::Mat trackerFrame = trackFrame->getCvFrame();
168 auto trackletsData = track->tracklets;
169 for(
auto& t : trackletsData) {
170 auto roi = t.roi.denormalize(trackerFrame.cols, trackerFrame.rows);
171 int x1 = roi.topLeft().x;
172 int y1 = roi.topLeft().y;
173 int x2 = roi.bottomRight().x;
174 int y2 = roi.bottomRight().y;
176 uint32_t labelIndex = t.label;
177 std::string labelStr =
to_string(labelIndex);
181 cv::putText(trackerFrame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
183 std::stringstream idStr;
184 idStr <<
"ID: " << t.id;
185 cv::putText(trackerFrame, idStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
186 std::stringstream statusStr;
187 statusStr <<
"Status: " << t.status;
188 cv::putText(trackerFrame, statusStr.str(), cv::Point(x1 + 10, y1 + 60), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
190 cv::rectangle(trackerFrame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
193 std::stringstream fpsStr;
194 fpsStr <<
"NN fps:" << std::fixed << std::setprecision(2) <<
fps;
195 cv::putText(trackerFrame, fpsStr.str(), cv::Point(2, trackFrame->getHeight() - 4), cv::FONT_HERSHEY_TRIPLEX, 0.4, color);
197 cv::imshow(
"tracker", trackerFrame);
199 int key = cv::waitKey(1);
200 if(key ==
'q' || key ==
'Q') {