decomposeHomographyMat does not return the expected decomposition (Bug #4307)
Description
Hi,
I am integrating decomposeHomographyMat in our codebase. I noticed in my unit tests that the method returns incorrect results about 10-25% of the time. I have reproduced a case in the OpenCV unit tests framework and enclose the file here (test_homography_decomp.cpp). The data used does not seem to represent any specific configuration (or at least non that I could identify). Also, I have relaxed the threshold a LOT (from 0.001 to 1) to make sure that this is not due to a "tight threshold". I also copy/paste the test results at the end of this message, FYI.
The formula used to generate the homography is (from Malis paper): H = R + t^{T}*n/d, where R is the rotation, t is the translation, n is the plane normal and d is the distance of the plane to the origin. Then H is scaled so that H(2,2) = 1.
Could you please confirm the bug and let me know when a fix is available? Please let me know if you need any further information (I did not include any platform, etc. details because you should be able to reproduce on any platform). I can also generate more failure cases if you need.
Thanks,
Philippe
-----------------------------------------------
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Test with OpenCV original data:
- VIDEOINPUT LIBRARY - 0.1995 - TFW07 ***
OpenCV version: 3.0.0-dev
OpenCV VCS version: unknown
Build type: debug
Parallel framework: ms-concurrency
CPU features: popcnt mmx sse sse2 sse3 ssse3 sse4.1 sse4.2
OpenCL Platforms:
NVIDIA CUDA
dGPU: GeForce GTX 970 (OpenCL 1.1 CUDA)
Current OpenCL device:
Type = dGPU
Name = GeForce GTX 970
Version = OpenCL 1.1 CUDA
Compute units = 13
Max work group size = 1024
Local memory size = 47 kB 1023 B
Max memory allocation size = 1 GB
Double support = Yes
Host unified memory = No
Has AMD Blas = No
Has AMD Fft = No
Preferred vector width char = 1
Preferred vector width short = 1
Preferred vector width int = 1
Preferred vector width long = 1
Preferred vector width float = 1
Preferred vector width double = 1
Note: Google Test filter = Calib3d_DecomposeHomography
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Calib3d_DecomposeHomography
[ RUN ] Calib3d_DecomposeHomography.regression
[ OK ] Calib3d_DecomposeHomography.regression (0 ms)
[----------] 1 test from Calib3d_DecomposeHomography (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[ PASSED ] 1 test.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Test with new data (in uploaded file):
- VIDEOINPUT LIBRARY - 0.1995 - TFW07 ***
OpenCV version: 3.0.0-dev
OpenCV VCS version: unknown
Build type: debug
Parallel framework: ms-concurrency
CPU features: popcnt mmx sse sse2 sse3 ssse3 sse4.1 sse4.2
OpenCL Platforms:
NVIDIA CUDA
dGPU: GeForce GTX 970 (OpenCL 1.1 CUDA)
Current OpenCL device:
Type = dGPU
Name = GeForce GTX 970
Version = OpenCL 1.1 CUDA
Compute units = 13
Max work group size = 1024
Local memory size = 47 kB 1023 B
Max memory allocation size = 1 GB
Double support = Yes
Host unified memory = No
Has AMD Blas = No
Has AMD Fft = No
Preferred vector width char = 1
Preferred vector width short = 1
Preferred vector width int = 1
Preferred vector width long = 1
Preferred vector width float = 1
Preferred vector width double = 1
Note: Google Test filter = Calib3d_DecomposeHomography
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Calib3d_DecomposeHomography
[ RUN ] Calib3d_DecomposeHomography.regression
..\..\..\modules\calib3d\test\test_homography_decomp.cpp(78): error: Value of: containsValidMotion(rotations, translations, normals)
Actual: false
Expected: true
[ FAILED ] Calib3d_DecomposeHomography.regression (0 ms)
[----------] 1 test from Calib3d_DecomposeHomography (1 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (2 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] Calib3d_DecomposeHomography.regression
History
Updated by Philippe Bouttefroy almost 10 years ago
The data that I provided is actually not consistent - I provided a homography with the translation denormalized but provided a normalized translation. The data below is consistent now:
_K = Matx33d(1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0);
_H = Matx33d(-0.102896, 0.270191, -0.0031153,
0.0406387, 1.19569, -0.0120456,
0.445351, 0.0410889, 1);
//expected solution for the given homography and intrinsic matrices
_R = Matx33d(0.692477, 0.657668, -0.29656,
-0.615501, 0.753003, 0.232688,
0.376343, 0.0214022, 0.926233);
_t = Vec3d(0.934629,
-0.775506,
-0.0368358);
_n = Vec3d(-0.841608,
-0.43925,
0.314254);
Matx33d h = _R + (_t * _n.t());
double norm = h(2, 2);
h = (1 / norm)*h;
std::cout << h << std::endl;
Updated by Maksim Shabunin over 9 years ago
Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4978