undistort() and remap() give different results

asked 2020-09-29 06:44:22 -0600

Shassk gravatar image

I was trying to figure out things for my previous question but suddenly found out that undistort() and remap() give different results.

Any ideas why can it be and what result can be considered more "correct"?

remap:

remap

undistort:

undistort

edit retag flag offensive close merge delete

Comments

post data and runnable code that reproduce this issue.

crackwitz gravatar imagecrackwitz ( 2020-09-30 08:29:15 -0600 )edit

Sorry for such a late response, for some reason I did not get notification on email about your comment, still figuring out how to set up this properly. Here's the link: source code and a folder with images. At first run it creates maps.yml with data for undistort/remap, on second — loads it from the file and applies to a single image. UPD: Source is in C++

Shassk gravatar imageShassk ( 2020-10-28 06:30:32 -0600 )edit

I can only speculate that one of the functions "crops" the picture (by manipulating the camera matrix) such that the picture contains as little black border and as much image content as possible. that was something I saw in the docs a long time ago, so it may not be the case now. either way, remap is a generic operation that relies on something else generating the map. undistort() applies the transformation directly, initUndistortRectifyMap() constructs the hopefully identical maps for a remap() call. it does contain "rectify" in the name, so it probably does more than just undistort.

crackwitz gravatar imagecrackwitz ( 2020-11-12 06:13:21 -0600 )edit

I looked through your code and compared it to docs. undistort: "The function is simply a combination of initUndistortRectifyMap (with unity R ) and remap (with bilinear interpolation)". your call to initUndistortRectifyMap doesn't pass a unity R (identity matrix) but an empty R. I think that could be the difference. I think "getOptimalNewCameraMatrix" is involved... that could explain the shift/crop you see.

crackwitz gravatar imagecrackwitz ( 2020-11-12 06:19:15 -0600 )edit