@@ -44,6 +44,7 @@ class gui_window_implementation {
4444 int calibrate (bool show = true );
4545 Mat dark;
4646 Matx<double , least_sq_size, 1 > filter_coef;
47+ cv::aruco::ArucoDetector aruco_detector;
4748 double lower, upper;
4849 Mat getLabelImage (bool show);
4950 void camLoop (std::stop_token st);
@@ -379,6 +380,12 @@ gui_window_implementation::gui_window_implementation(int window_width_, int wind
379380 cap.set (CAP_PROP_AUTOFOCUS, 0 );
380381// zoom_absolute 0x009a090d (int) : min=100 max=500 step=1 default=100 value=100 flags=has-min-max
381382
383+ cv::aruco::DetectorParameters detectorParams = cv::aruco::DetectorParameters ();
384+ detectorParams.adaptiveThreshWinSizeStep = 5 ;
385+ cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary (cv::aruco::DICT_4X4_250);
386+ aruco_detector = cv::aruco::ArucoDetector (dictionary, detectorParams);
387+
388+
382389
383390 SDL_Init (SDL_INIT_VIDEO);
384391
@@ -461,7 +468,7 @@ gui_window_implementation::gui_window_implementation(int window_width_, int wind
461468
462469 // std::latch calibrated(2);
463470 output (" Calibrating...\n " );
464- calibrate (false );
471+ calibrate (true );
465472 output (" Calibrated\n " );
466473 destroyAllWindows ();
467474 // camThread = std::jthread{[this](std::stop_token st) {
@@ -497,7 +504,7 @@ Mat gui_window_implementation::getLabelImage(bool show) {
497504 gr -= all[i] * filter_coef (i,0 );
498505 }
499506 gray.at <unsigned char >(x,y) = gr + 128 ;
500- if (gr < -20 ) {
507+ if (gr < -40 ) {
501508 low.at <unsigned char >(x, y) = 255 ;
502509 } else {
503510 low.at <unsigned char >(x, y) = 0 ;
@@ -522,8 +529,8 @@ Mat gui_window_implementation::getLabelImage(bool show) {
522529 }
523530 for (int r = 0 ; r < labelImage.rows ; ++r) {
524531 for (int c = 0 ; c < labelImage.cols ; ++c) {
525- int label = labelImage.at <int >(r, c);
526- int type;
532+ auto & label = labelImage.at <int >(r, c);
533+ int type = 0 ;
527534 if (label == 0 ) {
528535 type = 0 ;
529536 } else if (label == idx_b) {
@@ -539,6 +546,40 @@ Mat gui_window_implementation::getLabelImage(bool show) {
539546 label = type;
540547 }
541548 }
549+
550+ vector<int > ids;
551+ vector<vector<Point2f> > corners, rejected;
552+
553+ // detect markers and estimate pose
554+ aruco_detector.detectMarkers (myImage, corners, ids, rejected);
555+
556+ size_t nMarkers = corners.size ();
557+ vector<Vec3d> rvecs (nMarkers), tvecs (nMarkers);
558+
559+ Mat graycopy;
560+ gray.copyTo (graycopy);
561+ if (!ids.empty ()) {
562+ for (size_t i=0 ; i<ids.size (); i++) {
563+ {
564+ vector<Point2i> cr (corners[i].begin (), corners[i].end ());
565+ // fillPoly(labelImage, cr,1);
566+ }
567+ {
568+ auto & cr = corners[i];
569+ double cx = ( cr[3 ].x + cr[2 ].x + cr[1 ].x + cr[0 ].x )/4 .;
570+ double cy = ( cr[3 ].y + cr[2 ].y + cr[1 ].y + cr[0 ].y )/4 .;
571+ double vx = ( -cr[3 ].y - cr[2 ].x + cr[1 ].y + cr[0 ].x )/4 .;
572+ double vy = ( cr[3 ].x - cr[2 ].y - cr[1 ].x + cr[0 ].y )/4 .;
573+ circle (labelImage, Point2i (cx,cy), 70 , 1 , FILLED);
574+ }
575+ }
576+ cv::aruco::drawDetectedMarkers (graycopy, corners, ids);
577+ }
578+
579+ if (!rejected.empty ()) {
580+ cv::aruco::drawDetectedMarkers (graycopy, rejected, noArray (), Scalar (100 , 0 , 255 ));
581+ }
582+
542583 if (show) {
543584 Vec3b col0 (0 , 0 , 0 );
544585 Vec3b col1 (255 , 255 , 255 );
@@ -570,6 +611,11 @@ Mat gui_window_implementation::getLabelImage(bool show) {
570611 int v = gray.at <unsigned char >(r, c);
571612 pixel = Vec3b (v,v,v);
572613 }
614+ {
615+ Vec3b &pixel = dst.at <Vec3b>(binImage.rows +r, binImage.cols +c);
616+ int v = graycopy.at <unsigned char >(r, c);
617+ pixel = Vec3b (v,v,v);
618+ }
573619 }
574620 }
575621 // imshow("Color", myImage);
0 commit comments