Skip to content

Commit

Permalink
#111 add ArucoDetector cpp (not tested)
Browse files Browse the repository at this point in the history
  • Loading branch information
anacg1620 committed Jun 7, 2024
1 parent 6e9138d commit 45dcff5
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions libraries/YarpPlugins/ArucoDetector/ArucoDetector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-

#include "ArucoDetector.hpp"

#include <vector>

using namespace roboticslab;

bool ArucoDetector::open(yarp::os::Searchable& config)
{
// default params
detectorParams = cv::aruco::DetectorParameters();
dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
}

bool ArucoDetector::detect(const yarp::sig::Image& inYarpImg, yarp::os::Bottle& detectedObjects)
{
yarp::sig::ImageOf<yarp::sig::PixelBgr> inYarpImgBgr;
inYarpImgBgr.copy(inYarpImg);
cv::Mat inCvMat = yarp::cv::toCvMat(inYarpImgBgr);

std::vector<int> markerIds;
std::vector<std::vector<cv::Point2f>> corners, rejectedCandidates;

cv::aruco::ArucoDetector arucoDetector(dictionary, detectorParams);
arucoDetector.detectMarkers(inputImage, corners, markerIds, rejectedCandidates);

for (auto i = 0; i < corners.size() / 4; i++)
{
const auto & tl = corners[4 * i];
const auto & tr = corners[4 * i + 1];
const auto & br = corners[4 * i + 2];
const auto & bl = corners[4 * i + 3];

detectedObjects.addDict() = {
{"tlx", yarp::os::Value(tl.x)},
{"tly", yarp::os::Value(tl.y)},
{"trx", yarp::os::Value(tr.x)},
{"try", yarp::os::Value(tr.y)},
{"brx", yarp::os::Value(br.x)},
{"bry", yarp::os::Value(br.y)},
{"blx", yarp::os::Value(bl.x)},
{"bly", yarp::os::Value(bl.y)}
};
}

return true;
}

0 comments on commit 45dcff5

Please sign in to comment.