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"};
12 int main(
int argc,
char** argv) {
16 std::string nnPath(BLOB_PATH);
20 nnPath = std::string(argv[1]);
24 printf(
"Using blob at path: %s\n", nnPath.c_str());
44 videoOut->setStreamName(
"h265");
53 monoRight->setCamera(
"right");
60 depth->setRectifyEdgeFillColor(0);
62 nn->setConfidenceThreshold(0.5);
63 nn->setBlobPath(nnPath);
64 nn->setNumInferenceThreads(2);
65 nn->input.setBlocking(
false);
72 camRgb->video.link(videoEncoder->input);
73 videoEncoder->bitstream.link(videoOut->input);
75 monoRight->
out.
link(depth->right);
76 monoLeft->
out.
link(depth->left);
77 depth->disparity.link(disparityOut->
input);
78 depth->rectifiedRight.link(manip->inputImage);
79 manip->out.link(nn->input);
80 manip->out.link(manipOut->
input);
84 float disparityMultiplier = 255 / depth->initialConfig.getMaxDisparity();
99 cv::Mat frameDisparity;
100 std::vector<dai::ImgDetection> detections;
101 int offsetX = (monoRight->getResolutionWidth() - monoRight->getResolutionHeight()) / 2;
102 auto color = cv::Scalar(255, 0, 0);
104 auto videoFile = std::ofstream(
"video.h265", std::ios::binary);
105 cv::namedWindow(
"right", cv::WINDOW_NORMAL);
106 cv::namedWindow(
"manip", cv::WINDOW_NORMAL);
115 videoFile.write((
char*)out1->
getData().data(), out1->
getData().size());
126 frameDisparity = inDisparity->getCvFrame();
127 frameDisparity.convertTo(frameDisparity, CV_8UC1, disparityMultiplier);
128 cv::applyColorMap(frameDisparity, frameDisparity, cv::COLORMAP_JET);
132 detections = inDet->detections;
136 for(
auto& detection : detections) {
137 int x1 = detection.xmin * monoRight->getResolutionHeight() + offsetX;
138 int y1 = detection.ymin * monoRight->getResolutionHeight();
139 int x2 = detection.xmax * monoRight->getResolutionHeight() + offsetX;
140 int y2 = detection.ymax * monoRight->getResolutionHeight();
142 uint32_t labelIndex = detection.label;
143 std::string labelStr =
to_string(labelIndex);
147 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
148 std::stringstream confStr;
149 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
150 cv::putText(frame, confStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
151 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
154 cv::imshow(
"right", frame);
157 if(!frameDisparity.empty()) {
158 for(
auto& detection : detections) {
159 int x1 = detection.xmin * monoRight->getResolutionHeight() + offsetX;
160 int y1 = detection.ymin * monoRight->getResolutionHeight();
161 int x2 = detection.xmax * monoRight->getResolutionHeight() + offsetX;
162 int y2 = detection.ymax * monoRight->getResolutionHeight();
164 uint32_t labelIndex = detection.label;
165 std::string labelStr =
to_string(labelIndex);
169 cv::putText(frameDisparity, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
170 std::stringstream confStr;
171 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
172 cv::putText(frameDisparity, confStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
173 cv::rectangle(frameDisparity, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
176 cv::imshow(
"disparity", frameDisparity);
179 if(!frameManip.empty()) {
180 for(
auto& detection : detections) {
181 int x1 = detection.xmin * frameManip.cols;
182 int y1 = detection.ymin * frameManip.rows;
183 int x2 = detection.xmax * frameManip.cols;
184 int y2 = detection.ymax * frameManip.rows;
186 uint32_t labelIndex = detection.label;
187 std::string labelStr =
to_string(labelIndex);
191 cv::putText(frameManip, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
192 std::stringstream confStr;
193 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
194 cv::putText(frameManip, confStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
195 cv::rectangle(frameManip, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
198 cv::imshow(
"manip", frameManip);
201 int key = cv::waitKey(1);
202 if(key ==
'q' || key ==
'Q') {
206 cout <<
"To view the encoded data, convert the stream file (.h265) into a video file (.mp4), using a command below:" << endl;
207 cout <<
"ffmpeg -framerate 30 -i video.h265 -c copy video.mp4" << endl;