8 static const std::vector<std::string>
labelMap = {
"background",
"aeroplane",
"bicycle",
"bird",
"boat",
"bottle",
"bus",
9 "car",
"cat",
"chair",
"cow",
"diningtable",
"dog",
"horse",
10 "motorbike",
"person",
"pottedplant",
"sheep",
"sofa",
"train",
"tvmonitor"};
14 int main(
int argc,
char** argv) {
16 using namespace std::chrono;
17 std::string nnPath(BLOB_PATH);
21 nnPath = std::string(argv[1]);
25 printf(
"Using blob at path: %s\n", nnPath.c_str());
41 xoutRgb->setStreamName(
"preview");
45 camRgb->setPreviewSize(300, 300);
47 camRgb->setInterleaved(
false);
51 monoLeft->setCamera(
"left");
59 stereo->setOutputSize(monoLeft->getResolutionWidth(), monoLeft->getResolutionHeight());
61 spatialDetectionNetwork->setBlobPath(nnPath);
62 spatialDetectionNetwork->setConfidenceThreshold(0.5f);
63 spatialDetectionNetwork->input.setBlocking(
false);
64 spatialDetectionNetwork->setBoundingBoxScaleFactor(0.5);
65 spatialDetectionNetwork->setDepthLowerThreshold(100);
66 spatialDetectionNetwork->setDepthUpperThreshold(5000);
68 objectTracker->setDetectionLabelsToTrack({15});
75 monoLeft->out.link(stereo->left);
76 monoRight->
out.
link(stereo->right);
78 camRgb->preview.link(spatialDetectionNetwork->input);
79 objectTracker->passthroughTrackerFrame.link(xoutRgb->input);
80 objectTracker->out.link(trackerOut->
input);
83 camRgb->setPreviewKeepAspectRatio(
false);
84 camRgb->video.link(objectTracker->inputTrackerFrame);
85 objectTracker->inputTrackerFrame.setBlocking(
false);
87 objectTracker->inputTrackerFrame.setQueueSize(2);
89 spatialDetectionNetwork->passthrough.link(objectTracker->inputTrackerFrame);
92 spatialDetectionNetwork->passthrough.link(objectTracker->inputDetectionFrame);
93 spatialDetectionNetwork->out.link(objectTracker->inputDetections);
94 stereo->depth.link(spatialDetectionNetwork->inputDepth);
102 auto startTime = steady_clock::now();
105 auto color = cv::Scalar(255, 255, 255);
112 auto currentTime = steady_clock::now();
113 auto elapsed = duration_cast<duration<float>>(currentTime - startTime);
114 if(elapsed > seconds(1)) {
115 fps = counter / elapsed.count();
117 startTime = currentTime;
120 cv::Mat frame = imgFrame->getCvFrame();
121 auto trackletsData = track->tracklets;
122 for(
auto& t : trackletsData) {
123 auto roi = t.roi.denormalize(frame.cols, frame.rows);
124 int x1 = roi.topLeft().x;
125 int y1 = roi.topLeft().y;
126 int x2 = roi.bottomRight().x;
127 int y2 = roi.bottomRight().y;
129 uint32_t labelIndex = t.label;
130 std::string labelStr =
to_string(labelIndex);
134 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, 255);
136 std::stringstream idStr;
137 idStr <<
"ID: " << t.id;
138 cv::putText(frame, idStr.str(), cv::Point(x1 + 10, y1 + 35), cv::FONT_HERSHEY_TRIPLEX, 0.5, 255);
139 std::stringstream statusStr;
140 statusStr <<
"Status: " << t.status;
141 cv::putText(frame, statusStr.str(), cv::Point(x1 + 10, y1 + 50), cv::FONT_HERSHEY_TRIPLEX, 0.5, 255);
143 std::stringstream depthX;
144 depthX <<
"X: " << (int)t.spatialCoordinates.x <<
" mm";
145 cv::putText(frame, depthX.str(), cv::Point(x1 + 10, y1 + 65), cv::FONT_HERSHEY_TRIPLEX, 0.5, 255);
146 std::stringstream depthY;
147 depthY <<
"Y: " << (int)t.spatialCoordinates.y <<
" mm";
148 cv::putText(frame, depthY.str(), cv::Point(x1 + 10, y1 + 80), cv::FONT_HERSHEY_TRIPLEX, 0.5, 255);
149 std::stringstream depthZ;
150 depthZ <<
"Z: " << (int)t.spatialCoordinates.z <<
" mm";
151 cv::putText(frame, depthZ.str(), cv::Point(x1 + 10, y1 + 95), cv::FONT_HERSHEY_TRIPLEX, 0.5, 255);
153 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
156 std::stringstream fpsStr;
157 fpsStr <<
"NN fps: " << std::fixed << std::setprecision(2) <<
fps;
158 cv::putText(frame, fpsStr.str(), cv::Point(2, imgFrame->getHeight() - 4), cv::FONT_HERSHEY_TRIPLEX, 0.4, color);
160 cv::imshow(
"tracker", frame);
162 int key = cv::waitKey(1);