Repository navigation
New computeECC function, and updated findTransformECC function to make gaussian filtering optional - #13837
Conversation
|
@alalek : Apologies if you're not the person to get in touch about this, but the error here: https://pullrequest.opencv.org/buildbot/builders/precommit_linux64/builds/20152/steps/Compare%20ABI%20dumps/logs/report-html seems to be that the abi has changed. This is intentional, as I added a new optional argument to the function. I didn't find anything specific about handling such changes in the contribute page: could you please help and let me know if there's any other change I need to make to make this test pass? Local build passes (Ubuntu 18.04.2 LTS) and the tests pass too (build/opencv_test_video). Thanks! |
| InputOutputArray warpMatrix, int motionType = MOTION_AFFINE, | ||
| TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), | ||
| InputArray inputMask = noArray()); | ||
| InputArray inputMask = noArray(), int gaussFiltSize = 5); |
There was a problem hiding this comment.
Need to keep original overload too.
Try this:
CV_EXPORTS_W
double findTransformECC(InputArray templateImage, InputArray inputImage,
InputOutputArray warpMatrix, int motionType,
TermCriteria criteria,
InputArray inputMask, int gaussFiltSize);
/** @overload */
CV_EXPORTS
double findTransformECC(InputArray templateImage, InputArray inputImage,
InputOutputArray warpMatrix, int motionType = MOTION_AFFINE,
TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001),
InputArray inputMask = noArray());
... .cpp ...
double findTransformECC(InputArray templateImage, InputArray inputImage,
InputOutputArray warpMatrix, int motionType,
TermCriteria criteria,
InputArray inputMask)
{
return findTransformECC(..., inputMask, 5)
}
There was a problem hiding this comment.
Thanks for all the help! This resolves the previous build issue: https://pullrequest.opencv.org/buildbot/builders/precommit_linux64/builds/20174/steps/Compare%20ABI%20dumps/logs/report-html
| findTransformECC | ||
| */ | ||
|
|
||
| CV_EXPORTS_W double computeECC(const Mat& templateImage, const Mat& inputImage, const Mat& inputMask); |
There was a problem hiding this comment.
-
Use
InputArrayin public API instead of direct Mat. -
inputMask
An optional maskinputMask = noArray()
-
which should be warped with the final warpMatrix in
order to provideWhat?
Re-check parameters documentation and their limitations (CV_8U/32F is not correct).
There was a problem hiding this comment.
Parameter description uses undefined "warpMatrix" (not used in this function at all).
There was a problem hiding this comment.
Ah: thank you again. Here's the latest version:
@PARAM inputImage single-channel input image to be warped to provide an image similar to
templateImage, same type as templateImage.
| { | ||
| Scalar meanTemplate, sdTemplate; | ||
|
|
||
| meanStdDev(templateImage, meanTemplate, sdTemplate, inputMask); |
| } | ||
|
|
||
| bool CV_ECC_Test_Compute::testCompute(int) | ||
| { |
There was a problem hiding this comment.
Lets avoid using of legacy testing framework.
Just use Google Test:
TEST(Video_ECC_Test_Compute, accuracy)
{
Mat testImg = (Mat_<float>(3, 3) << 1, 0, 0, 1, 0, 0, 1, 0, 0);
Mat warpedImage = (Mat_<float>(3, 3) << 0, 1, 0, 0, 1, 0, 0, 1, 0);
Mat_<unsigned char> mask = Mat_<unsigned char>::ones(testImg.rows, testImg.cols);
double ecc = computeECC(warpedImage, testImg, mask);
EXPECT_NEAR(ecc, -0.5f, 1e-5f);
}
There was a problem hiding this comment.
Done: Thanks for writing out the Google Test version.
| double cv::computeECC(InputArray templateImage, InputArray inputImage, InputArray inputMask) | ||
| { | ||
| Mat src = templateImage.getMat(); | ||
| Mat dst = inputImage.getMat(); |
There was a problem hiding this comment.
dst = inputImage
This doesn't look consistent.
It is better to declare parameters with underscore _ suffix (in .cpp file only, keep .hpp without this hack). For "Mat" use original names.
double cv::computeECC(InputArray templateImage_, InputArray inputImage_, InputArray inputMask)
{
Mat templateImage = templateImage_.getMat();
Mat inputImage = inputImage_.getMat();
Anyway, you don't need to extract Mat from InputArray. Just use "InputArray" directly:
.cols->.cols().rows->.rows()- or
Mat::ones(src.rows, src.cols, ...)->Mat::ones(templateImage.size(), ...)
There was a problem hiding this comment.
Thanks for your patient guidance. Done.
| CV_Error( Error::StsUnmatchedFormats, "Both input images must have the same data type" ); | ||
|
|
||
| if(inputMask.empty()) | ||
| inputMaskMat = Mat::ones(src.rows, src.cols, CV_8U); |
There was a problem hiding this comment.
You don't need this.
Keep inputMask = noArray() - it is more faster.
Also cache countNonZero(inputMask) value (with override for the case of "no mask"):
int active_pixels = inputMask.empty() ? templateImage.size().area() : countNonZero(inputMask);
There was a problem hiding this comment.
That makes sense to me. Thank you once again.
There was a problem hiding this comment.
Is it possible that python wrapper requires inputMask to be explicitly passed?
(cc, warp_matrix) = cv2.findTransformECC(im1_gray,im2_gray,warp_matrix, warp_mode, criteria)
TypeError: Required argument 'inputMask' (pos 6) not found
|
Thank you for update! It is better to put this patch into 3.4 branch (there are no strong dependencies on "master" features, also it makes support easier). Please squash and rebase your commits:
Note: no needs to re-open PR, apply changes "inplace". |
|
@alalek Don't know if I did it right, but I followed your instructions and I suppose the branch is set to 3.4 and the checks have passed. Please do let me know if there's anything else I can do. Thank you very much for your patience and reviews! |
| InputArray inputMask, int gaussFiltSize); | ||
|
|
||
| /** @overload */ | ||
| CV_EXPORTS |
There was a problem hiding this comment.
Perhaps we need to use CV_EXPORTS_W here.
/cc @mixmixmix
New computeECC function, and updated findTransformECC function to make gaussian filtering optional (opencv#13837) * fix for opencv#12432 with doc and tests * Added doc string for new parameter. * Fixes suggested by Alalek for getting around ABI incompatibility. * Update to docstring, to remove parameter that isn't relevant. * More updates based on Alalek's usggestions.
resolves #12432
This pullrequest changes
The issue tracked in #12432 is resolved with the changes here, by adding a new function called computeECC as suggested by the issue author, and, by adding another optional argument to findTransformECC to control the size of the Gaussian filter (set to default of 5, to maintain backward compatibility; set to 1 to do no filtering, like the issue author would like). Tests and documentation strings are included as well.
This is my first pull request, and so pardon my tardiness.