Ask Your Question

Aruco (diamonds) not working on bigger images. Which parameters to tune?

asked 2017-08-04 07:34:07 -0500

cduguet gravatar image


somehow detecting charuco diamonds does not work with bigger images for me. With my original images of 1920x1080 it neither recognizes the ids reliably (the diamond ids elements are switching places every time). In the first image, you can see it recognizes (7, 9, 45, 2).

Then I tried downsampling the images to 960x540, and dividing the calibration params, f, c, to half, and it works! The id is correctly recognized as (2,7,45,9) and the pose estimation is accurate.

How to make it work for bigger images? I tried changing the detection parameters depending on absolute pixel units (not relative to image size). Here is a list of my current parameters.

nmarkers: 1024
adaptiveThreshWinSizeMin: 13
adaptiveThreshWinSizeMax: 43
adaptiveThreshWinSizeStep: 10
adaptiveThreshWinSize: 42
adaptiveThreshConstant: 7
minMarkerPerimeterRate: 0.1
maxMarkerPerimeterRate: 4.0
polygonalApproxAccuracyRate: 0.05
minCornerDistance: 10.0
minDistanceToBorder: 10
minMarkerDistance: 10.0
minMarkerDistanceRate: 0.05
doCornerRefinement: false
cornerRefinementWinSize: 5
cornerRefinementMaxIterations: 30
cornerRefinementMinAccuracy: 0.1
markerBorderBits: 1
perspectiveRemovePixelPerCell: 8
perspectiveRemoveIgnoredMarginPerCell: 0.13
maxErroneousBitsInBorderRate: 0.04
minOtsuStdDev: 5.0
errorCorrectionRate: 0.6

Any hints?

thank you!

image description

image description

edit retag flag offensive close merge delete


I think threshold is done here using adaptive threshold. try to increase winSize value

LBerger gravatar imageLBerger ( 2017-08-04 07:54:04 -0500 )edit

LBerger, thank you for yout comment. I tried before increasing the window size, but that that you mentioned I checked again and I see an increase in the recognition of the black squares, but not much in the ids and pose estimation.

it looks like this image: link text

cduguet gravatar imagecduguet ( 2017-08-04 08:07:41 -0500 )edit

try with winSize=185

LBerger gravatar imageLBerger ( 2017-08-04 09:14:04 -0500 )edit

I tried, without success. I came up with a solution for this, explained below.

cduguet gravatar imagecduguet ( 2017-08-09 08:32:03 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-08-09 08:41:28 -0500

cduguet gravatar image

Debugging my app I have noticed that minRepDistance inside detectCharucoDiamond is growing in squared proportion to the image width, and then its value is squared again for the thresholding using closestCandidateDistance inside of refineDetectedMarkers. So to supress this escalation 'to the fourth' of the image size, I have implemented the following patch in charuco.cpp (in the aruco module folder)

--- charuco.cpp 2017-08-09 14:01:38.583984613 +0200
+++ charuco.1.cpp   2017-08-09 14:01:08.972215628 +0200 @@ -738,7
+738,7 @@

     CV_Assert( > 0 && ==;

-    const float minRepDistanceRate = 0.12f;
+    const float minRepDistanceRate = 1.3024550356922115f;

     // create Charuco board layout for diamond (3x3 layout)
     Ptr<Dictionary> dict = getPredefinedDictionary(PREDEFINED_DICTIONARY_NAME(0)); @@ -771,7 +771,7 @@
           perimeterSq += edge.x*edge.x + edge.y*edge.y;
         // maximum reprojection error relative to perimeter
-        float minRepDistance = perimeterSq * minRepDistanceRate * minRepDistanceRate;
+        float minRepDistance = sqrt(perimeterSq) * minRepDistanceRate;

         int currentId = _markerIds.getMat().at< int >(i);

I came out with that (unneccesarily long) float minRepDistanceRate by trying to maintain the same threashold for a resolution of 640x480 when making the minRepDistance not quadratic anymore. Now when using it for 1920x1080, it works great!

edit flag offensive delete link more


who should I talk to to discuss if this is worth a pull request or not?

cduguet gravatar imagecduguet ( 2017-08-10 06:34:24 -0500 )edit

Question Tools



Asked: 2017-08-04 07:34:07 -0500

Seen: 808 times

Last updated: Aug 09 '17