11 cam->setInterleaved(
false);
12 cam->setIspScale(2, 3);
13 cam->setVideoSize(720, 720);
14 cam->setPreviewSize(300, 300);
18 cam->video.link(xoutRgb->input);
23 xin->setStreamName(
"in");
24 xin->out.link(script->inputs[
"toggle"]);
26 cam->preview.link(script->inputs[
"rgb"]);
30 msg = node.io['toggle'].tryGet()
32 toggle = msg.getData()[0]
33 node.warn('Toggle! Perform NN inferencing: ' + str(toggle))
34 frame = node.io['rgb'].get()
36 node.io['nn'].send(frame)
40 nn->setBlobPath(BLOB_PATH);
41 script->outputs[
"nn"].link(nn->input);
45 nn->out.link(xoutNn->input);
55 auto color = cv::Scalar(255, 127, 0);
57 auto drawDetections = [color](cv::Mat frame, std::vector<dai::ImgDetection>& detections) {
58 for(
auto& detection : detections) {
59 int x1 = detection.xmin * frame.cols;
60 int y1 = detection.ymin * frame.rows;
61 int x2 = detection.xmax * frame.cols;
62 int y2 = detection.ymax * frame.rows;
64 std::stringstream confStr;
65 confStr << std::fixed << std::setprecision(2) << detection.confidence * 100;
66 cv::putText(frame, confStr.str(), cv::Point(x1 + 10, y1 + 20), cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
67 cv::rectangle(frame, cv::Rect(cv::Point(x1, y1), cv::Point(x2, y2)), color, cv::FONT_HERSHEY_SIMPLEX);
74 if(imgDetections !=
nullptr) {
76 drawDetections(frame, detections);
78 std::string frameText =
"NN inferencing: ";
84 cv::putText(frame, frameText, cv::Point(20, 20), cv::FONT_HERSHEY_TRIPLEX, 0.7, color);
85 cv::imshow(
"Color frame", frame);
87 int key = cv::waitKey(1);
90 }
else if(key ==
't') {
92 std::cout <<
"Disabling\n";
94 std::cout <<
"Enabling\n";
98 std::vector<uint8_t> messageData;
99 messageData.push_back(runNn);
100 buf.setData(messageData);