Weird ArUco marker behavior
It is the first time I worked with ArUco markers and was disappointed by weird distortion after perspective transformation based on recognized markers. I assumed that its because of camera calibration errors and decided to test with "ideal" markers.
I calibrated camera with pattern file (not printed and photographed, but just from a source file). Then I generated my marker and put it on JPG image without any distortions. My program found the marker, I generated new position for marked and warped the image:
int side = 100;
resultCorners.push_back(corners[0][0]);
resultCorners.push_back(Point2f(corners[0][0].x + side, corners[0][0].y));
resultCorners.push_back(Point2f(corners[0][0].x + side, corners[0][0].y + side));
resultCorners.push_back(Point2f(corners[0][0].x, corners[0][0].y + side));
Mat w = getPerspectiveTransform(corners[0], resultCorners);
warpPerspective(img_copy, result, w, img_copy.size());
That worked OK: 1.PNG
Then I minimized source image with one pyrDown call and tried to recognize marker again:
Could you please explain, why this weird distortion happens and how I can avoid it in real situation with photo or video stream?
UPDATE: On the left is a source image, on the right - a destination. I find marker on both to make sure that code above turns source image in orthogonal projection to camera. I assume I should use vectors that I receive from estimatePoseSingleMarkers here, but for now I'm just confused with distortion of markers detected in source image.
In the second image, which is crooked, the source, or the result?
It looks like the marker in the source image isn't quite square. Which would obviously cause the result to be at least a little warped. Either that, or the detection is a bit off. I can't tell if it's the marker or just the detection box.
The second image is a result (on the right). 1.png ans 2.png are two attempts, where 2.png is just a little bit smaller. I just got idea to play with detection params.
Right, but in 2.png, is it the source image or just the detection box that is crooked? Since the detection box is drawn on top I can't see the original image.
Only detection box. Here are both source images: https://www.dropbox.com/s/mbvtjvc5pl3...
Yeah... that's blurring makes such result, just tested with the same size, just blurred image. Now wondering how to fix this situation, because in real photo there is always some portion of blurring.
Are you doing cornerSubPix? That may either help or hurt.
Or perhaps the refineDetectedMarkers function? Again, not sure if it would help or hurt.