9 using namespace std::chrono;
22 xoutAprilTag->setStreamName(
"aprilTagData");
35 aprilTag->passthroughInputImage.link(xoutAprilTagImage->
input);
37 manip->
out.
link(aprilTag->inputImage);
38 aprilTag->out.link(xoutAprilTag->input);
40 aprilTag->inputImage.setBlocking(
false);
41 aprilTag->inputImage.setQueueSize(1);
47 auto manipQueue = device.
getOutputQueue(
"aprilTagImage", 8,
false);
48 auto aprilTagQueue = device.
getOutputQueue(
"aprilTagData", 8,
false);
50 auto color = cv::Scalar(0, 255, 0);
52 auto startTime = steady_clock::now();
60 auto currentTime = steady_clock::now();
61 auto elapsed = duration_cast<duration<float>>(currentTime - startTime);
62 if(elapsed > seconds(1)) {
63 fps = counter / elapsed.count();
65 startTime = currentTime;
68 cv::Mat monoFrame = inFrame->
getFrame();
70 cv::cvtColor(monoFrame, frame, cv::COLOR_GRAY2BGR);
72 auto aprilTagData = aprilTagQueue->get<
dai::AprilTags>()->aprilTags;
73 for(
auto aprilTag : aprilTagData) {
74 auto& topLeft = aprilTag.topLeft;
75 auto& topRight = aprilTag.topRight;
76 auto& bottomRight = aprilTag.bottomRight;
77 auto& bottomLeft = aprilTag.bottomLeft;
79 cv::Point center = cv::Point((topLeft.x + bottomRight.x) / 2, (topLeft.y + bottomRight.y) / 2);
81 cv::line(frame, cv::Point(topLeft.x, topLeft.y), cv::Point(topRight.x, topRight.y), color, 2, cv::LINE_AA, 0);
82 cv::line(frame, cv::Point(topRight.x, topRight.y), cv::Point(bottomRight.x, bottomRight.y), color, 2, cv::LINE_AA, 0);
83 cv::line(frame, cv::Point(bottomRight.x, bottomRight.y), cv::Point(bottomLeft.x, bottomLeft.y), color, 2, cv::LINE_AA, 0);
84 cv::line(frame, cv::Point(bottomLeft.x, bottomLeft.y), cv::Point(topLeft.x, topLeft.y), color, 2, cv::LINE_AA, 0);
86 std::stringstream idStr;
87 idStr <<
"ID: " << aprilTag.
id;
88 cv::putText(frame, idStr.str(), center, cv::FONT_HERSHEY_TRIPLEX, 0.5, color);
91 std::stringstream fpsStr;
92 fpsStr <<
"fps:" << std::fixed << std::setprecision(2) <<
fps;
93 cv::putText(frame, fpsStr.str(), cv::Point(2, inFrame->getHeight() - 4), cv::FONT_HERSHEY_TRIPLEX, 0.4, color);
95 cv::imshow(
"April tag frame", frame);
97 int key = cv::waitKey(1);