lood339 / SCCvSD

Sports Camera Calibration via Synthesic Data
BSD 2-Clause "Simplified" License
71 stars 19 forks source link

How to use "cv.findTransformECC" #8

Closed Chen94yue closed 3 years ago

Chen94yue commented 4 years ago

I tried to solve the warning: "'Warning: find transform failed. Set warp as identity". But I failed. I run the code with opencv-pytorch-3.4.1.15. The error message is: _, warp = cv.findTransformECC(im_src, im_dst, warp, cv.MOTION_HOMOGRAPHY, criteria) cv2.error: OpenCV(3.4.1) /io/opencv/modules/video/src/ecc.cpp:540: error: (-7) The algorithm stopped before its convergence. The correlation is going to be minimized. Images may be uncorrelated or non-overlapped in function findTransformECC

Is this function necessacy?

lood339 commented 4 years ago

Yes, this function is necessary. It is used to optimized the camera pose (homography). The same error hits me in testing. So, I simply skip it by setting an identity matrix.

Chen94yue commented 4 years ago

Is there any effective solution?

lood339 commented 4 years ago

In python, https://github.com/lood339/SCCvSD/blob/70c39728f0055f395ca5a494c3ff306c0e52c996/python/util/synthetic_util.py Line 59-66 is the solution. In C++, no effective solution.

Chen94yue commented 4 years ago

I understand this solution. But if you skip it by setting an identity matrix, the cv.findTransformECC function is not actually called, and you say this function is necessary. 🤷‍♂️

lood339 commented 4 years ago

To make sure we are on the same page. Case 1: When cv.findTransformECC works well, it is not skipped. warp is not an identify matrix. Case 2: It is skipped only if the function fails. warp is an identify matrix. Most of examples are case 1, a few examples are case 2. So, I say it is necessary. Hope that is clear.

Chen94yue commented 4 years ago

I mean, is it necessary for cv.findTransformECC to work well?

lood339 commented 4 years ago

Nice, we are in the same page. yes, ideally cv.findTransformECC should return an error flag instead of crash (c++ case). Except that, cv.findTransformECC works pretty well. I believe setting the warp as an identify matrix is a decent solution although it is not perfect.

felibol commented 4 years ago

I think so you can try to give more parameters to cv.findTransformECC function as stated below link the last two params are not anymore optional. You can just call it like _, warp = cv.findTransformECC(im_src, im_dst, warp, cv.MOTION_HOMOGRAPHY, criteria, None, 5) https://answers.opencv.org/question/212409/error-in-findtransformecc/

calee88 commented 3 years ago

I think so you can try to give more parameters to cv.findTransformECC function as stated below link the last to params are not anymore optional. You can just call it like _, warp = cv.findTransformECC(im_src, im_dst, warp, cv.MOTION_HOMOGRAPHY, criteria, None, 5) https://answers.opencv.org/question/212409/error-in-findtransformecc/

I followed felibol's solution and it worked. I think this issue can be closed.

lood339 commented 3 years ago

Thanks @felibol for the fix and @calee88 for the conformation! It is updated to the codebase.