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"};
11 int main(
int argc,
char** argv) {
15 std::string nnPath(BLOB_PATH);
19 nnPath = std::string(argv[1]);
23 printf(
"Using blob at path: %s\n", nnPath.c_str());
37 xoutRgb->setStreamName(
"rgb");
44 camRgb->setPreviewSize(300, 300);
45 camRgb->setInterleaved(
false);
49 nn->setConfidenceThreshold(0.5);
50 nn->setBlobPath(nnPath);
51 nn->setNumInferenceThreads(2);
55 camRgb->video.link(videoEncoder->input);
56 camRgb->preview.link(xoutRgb->input);
57 camRgb->preview.link(nn->
input);
58 videoEncoder->bitstream.link(videoOut->
input);
71 std::vector<dai::ImgDetection> detections;
74 auto displayFrame = [](std::string name, cv::Mat frame, std::vector<dai::ImgDetection>& detections) {
75 auto color = cv::Scalar(255, 0, 0);
77 for(
auto& detection : detections) {
78 int x1 = detection.xmin * frame.cols;
79 int y1 = detection.ymin * frame.rows;
80 int x2 = detection.xmax * frame.cols;
81 int y2 = detection.ymax * frame.rows;
83 uint32_t labelIndex = detection.label;
84 std::string labelStr =
to_string(labelIndex);
88 cv::putText(frame, labelStr, cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
89 std::stringstream confStr;
90 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
91 cv::putText(frame, confStr.str(), cv::Point(x1 + 10, y1 + 40), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
92 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
95 cv::imshow(name, frame);
98 auto videoFile = std::ofstream(
"video.h264", std::ios::binary);
105 videoFile.write((
char*)out->
getData().data(), out->
getData().size());
112 detections = inDet->detections;
116 displayFrame(
"rgb", frame, detections);
119 int key = cv::waitKey(1);
120 if(key ==
'q' || key ==
'Q') {
124 cout <<
"To view the encoded data, convert the stream file (.h265) into a video file (.mp4), using a command below:" << endl;
125 cout <<
"ffmpeg -framerate 30 -i video.h264 -c copy video.mp4" << endl;