mirror of
https://github.com/opencv/opencv.git
synced 2024-11-29 22:00:25 +08:00
ff48387a8a
The matrix templateZM needs to be initialized because otherwise uninitialized values leak into the correlation in: const double correlation = templateZM.dot(imageWarped) In the worst case this will lead the correlation to be NaN ruining the whole routine. The subtraction does not initialize templateZM due to the mask. Unfortunately, the uninitialized values (by altering the correlation) have the side effect of dragging out the computation a little longer giving a slightly better error bound. This means that fixing this bug breaks perf_ecc where SANITY_CHECK(warpMat, 1e-3); is just a little too tight and happens to work due to the uninitialized values. Since this is a performance not a accuracy test I think it is OK to just relax the error bound a little bit (the tight error bound being after all the result of a bug).
72 lines
2.3 KiB
C++
72 lines
2.3 KiB
C++
#include "perf_precomp.hpp"
|
|
|
|
using namespace std;
|
|
using namespace cv;
|
|
using namespace perf;
|
|
using std::tr1::make_tuple;
|
|
using std::tr1::get;
|
|
|
|
CV_ENUM(MotionType, MOTION_TRANSLATION, MOTION_EUCLIDEAN, MOTION_AFFINE, MOTION_HOMOGRAPHY)
|
|
|
|
typedef std::tr1::tuple<MotionType> MotionType_t;
|
|
typedef perf::TestBaseWithParam<MotionType_t> TransformationType;
|
|
|
|
|
|
PERF_TEST_P(TransformationType, findTransformECC, /*testing::ValuesIn(MotionType::all())*/
|
|
testing::Values((int) MOTION_TRANSLATION, (int) MOTION_EUCLIDEAN,
|
|
(int) MOTION_AFFINE, (int) MOTION_HOMOGRAPHY)
|
|
)
|
|
{
|
|
Mat img = imread(getDataPath("cv/shared/fruits_ecc.png"),0);
|
|
Mat templateImage;
|
|
|
|
int transform_type = get<0>(GetParam());
|
|
|
|
Mat warpMat;
|
|
Mat warpGround;
|
|
|
|
double angle;
|
|
switch (transform_type) {
|
|
case MOTION_TRANSLATION:
|
|
warpGround = (Mat_<float>(2,3) << 1.f, 0.f, 7.234f,
|
|
0.f, 1.f, 11.839f);
|
|
|
|
warpAffine(img, templateImage, warpGround,
|
|
Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
|
|
break;
|
|
case MOTION_EUCLIDEAN:
|
|
angle = CV_PI/30;
|
|
|
|
warpGround = (Mat_<float>(2,3) << (float)cos(angle), (float)-sin(angle), 12.123f,
|
|
(float)sin(angle), (float)cos(angle), 14.789f);
|
|
warpAffine(img, templateImage, warpGround,
|
|
Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
|
|
break;
|
|
case MOTION_AFFINE:
|
|
warpGround = (Mat_<float>(2,3) << 0.98f, 0.03f, 15.523f,
|
|
-0.02f, 0.95f, 10.456f);
|
|
warpAffine(img, templateImage, warpGround,
|
|
Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
|
|
break;
|
|
case MOTION_HOMOGRAPHY:
|
|
warpGround = (Mat_<float>(3,3) << 0.98f, 0.03f, 15.523f,
|
|
-0.02f, 0.95f, 10.456f,
|
|
0.0002f, 0.0003f, 1.f);
|
|
warpPerspective(img, templateImage, warpGround,
|
|
Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
|
|
break;
|
|
}
|
|
|
|
TEST_CYCLE()
|
|
{
|
|
if (transform_type<3)
|
|
warpMat = Mat::eye(2,3, CV_32F);
|
|
else
|
|
warpMat = Mat::eye(3,3, CV_32F);
|
|
|
|
findTransformECC(templateImage, img, warpMat, transform_type,
|
|
TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 5, -1));
|
|
}
|
|
SANITY_CHECK(warpMat, 3e-3);
|
|
}
|