This commit is contained in:
ackimixs
2024-01-24 16:12:44 +01:00
parent a3b9ae3c06
commit d83ccff03d
3 changed files with 20 additions and 16 deletions

View File

@@ -3,12 +3,12 @@
ArucoDetector::ArucoDetector(const Type::RobotPose& pose, const std::string& calibrationPath, const Team team, const int cameraId, const bool headless) : robotPose(pose), headless(headless), team(team) ArucoDetector::ArucoDetector(const Type::RobotPose& pose, const std::string& calibrationPath, const Team team, const int cameraId, const bool headless) : robotPose(pose), headless(headless), team(team)
{ {
// opencv 4.8 // opencv 4.8
this->detector = cv::aruco::ArucoDetector(getPredefinedDictionary(cv::aruco::DICT_4X4_50), cv::aruco::DetectorParameters()); // this->detector = cv::aruco::ArucoDetector(getPredefinedDictionary(cv::aruco::DICT_4X4_50), cv::aruco::DetectorParameters());
this->dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50); // this->dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50);
this->parameters = cv::aruco::DetectorParameters(); // this->parameters = cv::aruco::DetectorParameters();
// 4.6 // 4.6
// this->dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50); this->dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_4X4_50);
this->transformationMatrix = (cv::Mat_<double>(4, 4) << this->transformationMatrix = (cv::Mat_<double>(4, 4) <<
@@ -73,11 +73,6 @@ void ArucoDetector::addArucoTag(const ArucoTag& tag)
std::pair<int, std::vector<std::pair<ArucoTag, std::pair<cv::Mat, cv::Mat>>>> ArucoDetector::detectArucoTags(std::vector<ArucoTag> tags) std::pair<int, std::vector<std::pair<ArucoTag, std::pair<cv::Mat, cv::Mat>>>> ArucoDetector::detectArucoTags(std::vector<ArucoTag> tags)
{ {
if (tags.empty())
{
tags = this->arucoTags;
}
if (!started) if (!started)
{ {
std::pair<int, std::vector<std::pair<ArucoTag, std::pair<cv::Mat, cv::Mat>>>> result; std::pair<int, std::vector<std::pair<ArucoTag, std::pair<cv::Mat, cv::Mat>>>> result;
@@ -85,6 +80,11 @@ std::pair<int, std::vector<std::pair<ArucoTag, std::pair<cv::Mat, cv::Mat>>>> Ar
return result; return result;
} }
if (tags.empty())
{
tags = this->arucoTags;
}
cv::Mat frame; cv::Mat frame;
cap >> frame; // Capture frame from the camera cap >> frame; // Capture frame from the camera
@@ -102,10 +102,10 @@ std::pair<int, std::vector<std::pair<ArucoTag, std::pair<cv::Mat, cv::Mat>>>> Ar
std::vector<std::vector<cv::Point2f>> markerCorners; std::vector<std::vector<cv::Point2f>> markerCorners;
// 4.6 // 4.6
// cv::aruco::detectMarkers(frame, this->dictionary, markerCorners, markerIds); cv::aruco::detectMarkers(frame, this->dictionary, markerCorners, markerIds);
// opencv 4.8 // opencv 4.8
detector.detectMarkers(frame, markerCorners, markerIds); // detector.detectMarkers(frame, markerCorners, markerIds);
if (!markerIds.empty()) if (!markerIds.empty())
{ {
@@ -208,6 +208,10 @@ void ArucoDetector::solarPanelDetector(const ArucoTag& tag, cv::Mat translationM
{ {
std::cout << "Yellow side" << std::endl; std::cout << "Yellow side" << std::endl;
} }
else
{
std::cout << "Mid" << std::endl;
}
// BLUE => 90, YELLOW => -90 // BLUE => 90, YELLOW => -90
} }

View File

@@ -14,12 +14,12 @@ class ArucoDetector {
cv::VideoCapture cap; cv::VideoCapture cap;
// 4.6 // 4.6
// cv::Ptr<cv::aruco::Dictionary> dictionary; cv::Ptr<cv::aruco::Dictionary> dictionary;
// 4.8 // 4.8
cv::aruco::Dictionary dictionary; // cv::aruco::Dictionary dictionary;
cv::aruco::DetectorParameters parameters; // cv::aruco::DetectorParameters parameters;
cv::aruco::ArucoDetector detector; // cv::aruco::ArucoDetector detector;
bool headless; bool headless;

View File

@@ -64,7 +64,7 @@ int main(int argc, char *argv[])
auto solarPanel = ArucoTag(47, "Solar panel", 50, SOLAR_PANEL); auto solarPanel = ArucoTag(47, "Solar panel", 50, SOLAR_PANEL);
while (true) { while (true) {
const auto [code, res] = detector.detectArucoTags({solarPanel}); const auto [code, res] = detector.detectArucoTags({whiteFlower, purpleFlower, solarPanel});
if (code == -2) if (code == -2)
{ {