Ask Your Question
1

How to port image registration C++ code to Python

asked 2020-01-30 03:06:55 -0500

mastersom gravatar image

The python code below should register an image. The code is based on the example code map_test.cpp found here and also seen below. However I cannot seem to find the equivalent for casting map_ptr (which is a reg_Map object) to a map projection. The cpp code uses a .get() function. Performing this step is relevant as the normalize function is a class member of cv2.reg_MapProjec. In the code below, when I try to cast mat_ptr to map_proj, I get the error TypeError: Expected Ptr cv::UMat for argument '%s'. Does any know how to solve this issue?

Thanks in advance

def calc_homography_pixel(img1, img2):

    mapper = cv2.reg_MapperGradProj()
    mapp_pyr = cv2.reg_MapperPyramid(mapper)
    map_ptr = mapp_pyr.calculate(img1, img2)

    map_proj = cv2.reg_MapProjec(map_ptr) # the issue is how to the map from the pyramid cal.
    map_proj = map_proj.normalize()

    dest = map_proj.inverseWarp(img2)

The c++ code

static void calcHomographyPixel(const Mat& img1, const Mat& img2)
{
    static const char* diffpixel = "Difference pixel registered";

    Ptr<MapperGradProj> mapper = makePtr<MapperGradProj>();
    MapperPyramid mappPyr(mapper);
    Ptr<Map> mapPtr = mappPyr.calculate(img1, img2);

    MapProjec* mapProj = dynamic_cast<MapProjec*>(mapPtr.get());
    mapProj->normalize();
    cout << "--- Pixel-based method\n" << Mat(mapProj->getProjTr()) << endl;

    Mat dest;
    mapProj->inverseWarp(img2, dest);
    showDifference(img1, dest, diffpixel);
}
edit retag flag offensive close merge delete

Comments

1

Post an issue I think there is a bug in python binding. how to solve : create an PyMap class as PyRotationWrapper...

LBerger gravatar imageLBerger ( 2020-01-30 04:43:19 -0500 )edit

@LBerger, where do I post this issue? Can you be more elaborate? I am fairly new to this.

mastersom gravatar imagemastersom ( 2020-01-30 04:48:23 -0500 )edit

I found in the doc :

map_proj = cv.reg.MapTypeCaster_toProjec(map_ptr)
LBerger gravatar imageLBerger ( 2020-02-04 10:00:35 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-02-04 14:23:54 -0500

LBerger gravatar image

updated 2020-02-05 01:46:58 -0500

I found in the doc :

map_proj = cv.reg.MapTypeCaster_toProjec(map_ptr)

and there is no value return by normalize. normalise does work in place :

import cv2 as cv

img1 = cv.imread("g:/lib/opencv/samples/data/lena.jpg")
img2 = cv.imread("g:/lib/opencv/samples/data/lena.jpg")
mapper = cv.reg_MapperGradProj()
mapp_pyr = cv.reg_MapperPyramid(mapper)
map_ptr = mapp_pyr.calculate(img, img)
map_proj = cv.reg.MapTypeCaster_toProjec(map_ptr)
map_proj.normalize()

dest = map_proj.inverseWarp(img2)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-01-30 03:06:55 -0500

Seen: 75 times

Last updated: Feb 05