Skip to content

Commit

Permalink
fixed #316 aruco building on opencv 4.7 and above
Browse files Browse the repository at this point in the history
  • Loading branch information
goldbattle committed Oct 29, 2023
1 parent 78b3513 commit 64a58c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ov_core/src/test_tracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int main(int argc, char **argv) {
// Location of the ROS bag we want to read in
std::string path_to_bag;
nh->param<std::string>("path_bag", path_to_bag, "/home/patrick/datasets/euroc_mav/V1_01_easy.bag");
// nh->param<std::string>("path_bag", path_to_bag, "/home/patrick/datasets/open_vins/aruco_room_01.bag");
// nh->param<std::string>("path_bag", path_to_bag, "/home/patrick/datasets/rpng_aruco/aruco_room_01.bag");
PRINT_INFO("ros bag path is: %s\n", path_to_bag.c_str());

// Get our start location and how much of the bag we want to play
Expand Down
4 changes: 4 additions & 0 deletions ov_core/src/track/TrackAruco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ void TrackAruco::perform_tracking(double timestamp, const cv::Mat &imgin, size_t
//===================================================================================

// Perform extraction
#if CV_MAJOR_VERSION > 4 || ( CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
aruco_detector.detectMarkers(img0, corners[cam_id], ids_aruco[cam_id], rejects[cam_id]);
#else
cv::aruco::detectMarkers(img0, aruco_dict, corners[cam_id], ids_aruco[cam_id], aruco_params, rejects[cam_id]);
#endif
rT2 = boost::posix_time::microsec_clock::local_time();

//===================================================================================
Expand Down
17 changes: 16 additions & 1 deletion ov_core/src/track/TrackAruco.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ class TrackAruco : public TrackBase {
bool downsize)
: TrackBase(cameras, 0, numaruco, stereo, histmethod), max_tag_id(numaruco), do_downsizing(downsize) {
#if ENABLE_ARUCO_TAGS
#if CV_MAJOR_VERSION > 4 || ( CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
aruco_dict = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_1000);
aruco_params.cornerRefinementMethod = cv::aruco::CORNER_REFINE_SUBPIX;
aruco_detector = cv::aruco::ArucoDetector(aruco_dict, aruco_params);
#else
aruco_dict = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_1000);
aruco_params = cv::aruco::DetectorParameters::create();
// NOTE: people with newer opencv might fail here
// aruco_params->cornerRefinementMethod = cv::aruco::CornerRefineMethod::CORNER_REFINE_SUBPIX;
#endif
#else
PRINT_ERROR(RED "[ERROR]: you have not compiled with aruco tag support!!!\n" RESET);
std::exit(EXIT_FAILURE);
Expand Down Expand Up @@ -101,11 +107,20 @@ class TrackAruco : public TrackBase {
bool do_downsizing;

#if ENABLE_ARUCO_TAGS
#if CV_MAJOR_VERSION > 4 || ( CV_MAJOR_VERSION == 4 && CV_MINOR_VERSION >= 7)
// Our dictionary that we will extract aruco tags with
cv::aruco::Dictionary aruco_dict;
// Parameters the opencv extractor uses
cv::aruco::DetectorParameters aruco_params;
// Actual detector class
cv::aruco::ArucoDetector aruco_detector;
#else
// Our dictionary that we will extract aruco tags with
cv::Ptr<cv::aruco::Dictionary> aruco_dict;

// Parameters the opencv extractor uses
cv::Ptr<cv::aruco::DetectorParameters> aruco_params;
#endif


// Our tag IDs and corner we will get from the extractor
std::unordered_map<size_t, std::vector<int>> ids_aruco;
Expand Down

0 comments on commit 64a58c9

Please sign in to comment.