opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.33k stars 5.74k forks source link

cv::reg::MapperGradShift produce poor result in the given test code #1035

Open loslu opened 7 years ago

loslu commented 7 years ago
System information
Detailed description

test1 test2 When I run the function "testShift" in "reg/test/test_reg.cpp", I got a very poor result and it does not pass the test. I have tried many different images but it just cannot get the expected result. I give some of the image which I used for this test.

Steps to reproduce

The function can be found in line 79~105 in "opencv_contrib/modules/reg/test/test_reg.cpp" `

void RegTest::testShift()
{
    Mat img2;
    // Warp original image
    Vec<double, 2> shift(5., 5.);
    MapShift mapTest(shift);
    mapTest.warp(img1, img2);
    // Register
    Ptr<Mapper> mapper = makePtr<MapperGradShift>();
    MapperPyramid mappPyr(mapper);
    Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);

    // Print result
    Ptr<MapShift> mapShift = MapTypeCaster::toShift(mapPtr);
#if REG_DEBUG_OUTPUT
    cout << endl << "--- Testing shift mapper ---" << endl;
    cout << Mat(shift) << endl;
    cout << Mat(mapShift->getShift()) << endl;
#endif

    // Check accuracy
    Ptr<Map> mapInv(mapShift->inverseMap());
    mapTest.compose(mapInv);
    double shNorm = norm(mapTest.getShift());
    EXPECT_LE(shNorm, 0.1);
}

`

sovrasov commented 7 years ago

MapperGradShift tries to estimate only translation. It can't handle rotation and scale transform. Try MapperGradAffine instead.

sovrasov commented 7 years ago

I've tried to reproduce the issue using samples/reg_shift.py. This sample does the same as testShift(). Output is OK for the both images:

[[ 5.01191182]
 [ 4.99011373]]

and

[[ 4.98007132]
 [ 4.98344032]]
sovrasov commented 7 years ago

Probably you need to convert images into floating-point format before run mappers.

rochus-keller commented 6 years ago

The MapperGradShift seems only to work for offsets up to 13 pixels. If the shift variable is set to 14,14 in testShift, output is --- Testing shift mapper --- [14; 14] [11.19182019401037; 13.36567527138815] When the offset is increased, results become even worse. Is this a known restriction of the method or a bug?

Juddd commented 6 years ago

Could you help to answer this question?