Added initInverseRectificationMap()#20165
Conversation
|
@alalek I need instruction on how to incorporate a performance test. This can be done with a chessboard image and check the rms error between the original and captured points. Currently have a sloppy visual image comparison to check my implementation. ''' ''' |
|
@IanMaquignaz, thank you for the contribution!
|
Yes, not a problem. Please consider updating the contribution docs as I specifically rebased from master to 3.4 per the guidelines.
Gladly, just need to know how. Found \modules\calib3d\perf\perf_undistort.cpp but have not found any documentation on how it works. The easiest validation method is take the image of a chessboard and remap it using cv::initInverseRectificationMap() and cv::initUndistortRectifyMap(). This models light passing backwards and forwards through a lens, returning a result which should match the original chessboard closely. I can do an RMS error of chessboard correspondences between before and after images. |
cba4188 to
e73979d
Compare
e73979d to
b556d4d
Compare
|
Hi All, I spent quite a bit of time over the last two days trying to create a fisheye version of initInverseRectificationMap(). Thus far this has been unfruitful, with my solution exhibiting greater distortion than anticipated. It appears that cv::fisheye::undistortPoints() is both greatly impacted and impacting of the camera matrix in ways I don't yet fully understand. At this point in time (or at least for my currently application) I not longer believe initInverseRectificationMap() can be viably applicable to the fisheye camera model. cv::initInverseRectificationMap() should be good to go. The test case from cv::initUndistortRectifyMap() has been duplicated and altered to validate in the same fashion. No idea what the two failed checks are.... pullrequest.opencv.org shows all green. |
|
Need me to squash the commits? @vpisarev |
501d9ff to
426e9ab
Compare
…ionMap() Fixed trailing whitespace Update to initInverseRectificationMap documentation for clarity Added test case for initInverseRectificationMap() Updated documentation. Fixed whitespace error in docs Small update to test function Now passes success_error_level final update to inverseRectification documentation
acd9ad5 to
b056314
Compare
|
@IanMaquignaz, thank you for the contribution! 👍 |
|
@vpisarev Do NOT violate existed merge rules. Again, Merging is not allowed:
|
alalek
left a comment
There was a problem hiding this comment.
Changes are required, see below.
| Size size_w_h(512 + 3, 512); | ||
| Mat k(3, 3, CV_32FC1); | ||
| Mat d(1, 14, CV_64FC1); | ||
| Mat dst(size_w_h, CV_32FC2); | ||
| declare.in(k, d, WARMUP_RNG).out(dst); |
There was a problem hiding this comment.
Why do we have such non-standard size_w_h?
Why do we have randomized input for camera intrinsics? Prefer to measure the real cases.
Function is not a real-time, not optimized and really slow (30+ ms), so there is not enough reasons to enable it into default set of perf tests.
There was a problem hiding this comment.
Test has been disabled in #20247. New unit test is being developed to replace it.
| { | ||
| distCoeffs.create(14, 1, CV_64F); | ||
| distCoeffs = 0.; | ||
| } |
There was a problem hiding this comment.
Assigning distortion matrix probably slowdowns computations below for this path.
There was a problem hiding this comment.
Correct. cv::undistortPoints skips distortion entirely if the matrix is empty. Correction has been applied in #20247.
It is unfortunate the same optimization is not applied for R.
|
|
||
| //------------------------------------------------------ | ||
|
|
||
| class CV_InitInverseRectificationMapTest : public cvtest::ArrayTest |
There was a problem hiding this comment.
cvtest::ArrayTest
Adding new tests based on legacy classes should be avoided (they are deprecated since migration on Google Tests, ~10 years ago).
| TEST(Calib3d_DefaultNewCameraMatrix, accuracy) { CV_DefaultNewCameraMatrixTest test; test.safe_run(); } | ||
| TEST(Calib3d_UndistortPoints, accuracy) { CV_UndistortPointsTest test; test.safe_run(); } | ||
| TEST(Calib3d_InitUndistortRectifyMap, accuracy) { CV_InitUndistortRectifyMapTest test; test.safe_run(); } | ||
| TEST(Calib3d_InitInverseRectificationMap, accuracy) { CV_InitInverseRectificationMapTest test; test.safe_run(); } |
There was a problem hiding this comment.
This test consumes 33% of all opencv_test_calib3d run (30 seconds from 1:30).
This is not acceptable, test must be reduced to run in 1-2sec.
| void initInverseRectificationMap( const Mat& _a0, const Mat& _k0, const Mat& _R0, const Mat& _new_cam0, Size sz, Mat& __mapx, Mat& __mapy, int map_type ) | ||
| { |
There was a problem hiding this comment.
Do NOT touch the TS module!
Module-specific functionality should be moved out of this generic module instead.
There was a problem hiding this comment.
Code has been removed and integrated into test_undistort.cpp. Applied in #20247.
| CV_EXPORTS_W | ||
| void initInverseRectificationMap( InputArray cameraMatrix, InputArray distCoeffs, | ||
| InputArray R, InputArray newCameraMatrix, | ||
| Size size, int m1type, OutputArray map1, OutputArray map2 ); |
There was a problem hiding this comment.
Size size
const reference for all input parameters based on non-scalars: const Size& size
@alalek I had no idea what I was doing in developing this unit test. I have not found any documentation nor have received any guidance on how to approach creating this. As my function in essentially the inverse of InitUndistortRectify, I duplicated its test and performance tests. |
|
@alalek What's the correct procedure here? Can I make the requested changes and push them to this PR, or should I open a new one? |
|
@IanMaquignaz Don't worry. This is not your fault. It is reviewer responsibility to provide guidance according to actual development rules. This PR is merged, so please create a new PR with updates (please add link on this one in PR's description). |
|
@alalek what's a good unit test to copy and use as a base? Possibly TEST_F(fisheyeTest, undistortAndDistortImage)? though I frankly don't understand how it validates cv::fisheye::initUndistortRectifyMap(). The easiest validation method is take the image of a chessboard, and remap it using cv::initInverseRectificationMap() then cv::initUndistortRectifyMap(). This models light passing backwards and forwards through a lens, returning a result which should match the original unaltered chessboard. The chessboard correspondences can be compared for an accuracy metric. |
Yes something like this, or even
In general, avoid using of other OpenCV functions. Prefer to check results of tested function only. If you want, you can add "full" variant of test (like the current one) for development/optimization purposes, but please keep it disabled (add "DISABLED_" prefix to the name). |
This pull request adds a function to Calib3D to support inverse rectification in procam systems. Essentially, it provides the inverse of initUndistortRectifyMap() such that projectors are properly handled in stereo-rectified projector-camera pairs.
Why is this function needed? Inverse rectification has been incorrectly applied in many works, including mishandling of distortion coefficients. Hopefully this proposed function will help curb this trend.
Once successfully merged, a duplicate function can be added for fisheye calibration.
Pull Request Readiness Checklist
Patch to opencv_extra has the same branch name.