9 using namespace std::chrono;
21 xoutMono->setStreamName(
"mono");
26 monoLeft->setCamera(
"left");
31 aprilTag->passthroughInputImage.link(xoutMono->input);
32 monoLeft->
out.
link(aprilTag->inputImage);
35 aprilTag->inputImage.setBlocking(
false);
36 aprilTag->inputImage.setQueueSize(1);
39 auto aprilTagConfig = aprilTag->initialConfig.get();
40 aprilTagConfig.quadDecimate = 4;
41 aprilTagConfig.quadSigma = 0;
42 aprilTagConfig.refineEdges =
true;
43 aprilTagConfig.decodeSharpening = 0.25;
44 aprilTagConfig.maxHammingDistance = 1;
45 aprilTagConfig.quadThresholds.minClusterPixels = 5;
46 aprilTagConfig.quadThresholds.maxNmaxima = 10;
47 aprilTagConfig.quadThresholds.criticalDegree = 10;
48 aprilTagConfig.quadThresholds.maxLineFitMse = 10;
49 aprilTagConfig.quadThresholds.minWhiteBlackDiff = 5;
50 aprilTagConfig.quadThresholds.deglitch =
false;
51 aprilTag->initialConfig.set(aprilTagConfig);
58 auto aprilTagQueue = device.
getOutputQueue(
"aprilTagData", 8,
false);
60 auto color = cv::Scalar(0, 255, 0);
62 auto startTime = steady_clock::now();
70 auto currentTime = steady_clock::now();
71 auto elapsed = duration_cast<duration<float>>(currentTime - startTime);
72 if(elapsed > seconds(1)) {
73 fps = counter / elapsed.count();
75 startTime = currentTime;
78 cv::Mat monoFrame = inFrame->
getFrame();
80 cv::cvtColor(monoFrame, frame, cv::COLOR_GRAY2BGR);
82 auto aprilTagData = aprilTagQueue->get<
dai::AprilTags>()->aprilTags;
83 for(
auto aprilTag : aprilTagData) {
84 auto& topLeft = aprilTag.topLeft;
85 auto& topRight = aprilTag.topRight;
86 auto& bottomRight = aprilTag.bottomRight;
87 auto& bottomLeft = aprilTag.bottomLeft;
89 cv::Point center = cv::Point((topLeft.x + bottomRight.x) / 2, (topLeft.y + bottomRight.y) / 2);
91 cv::line(frame, cv::Point(topLeft.x, topLeft.y), cv::Point(topRight.x, topRight.y), color, 2, cv::LINE_AA, 0);
92 cv::line(frame, cv::Point(topRight.x, topRight.y), cv::Point(bottomRight.x, bottomRight.y), color, 2, cv::LINE_AA, 0);
93 cv::line(frame, cv::Point(bottomRight.x, bottomRight.y), cv::Point(bottomLeft.x, bottomLeft.y), color, 2, cv::LINE_AA, 0);
94 cv::line(frame, cv::Point(bottomLeft.x, bottomLeft.y), cv::Point(topLeft.x, topLeft.y), color, 2, cv::LINE_AA, 0);
96 std::stringstream idStr;
97 idStr <<
"ID: " << aprilTag.
id;
98 cv::putText(frame, idStr.str(), center, cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
101 std::stringstream fpsStr;
102 fpsStr <<
"fps:" << std::fixed << std::setprecision(2) <<
fps;
103 cv::putText(frame, fpsStr.str(), cv::Point(2, inFrame->getHeight() - 4), cv::FONT_HERSHEY_TRIPLEX, 0.4, color);
105 cv::imshow(
"mono", frame);
107 int key = cv::waitKey(1);