Ask Your Question
0

Help Needed with OpenCV reg: Modifying the map

asked 2016-04-04 11:06:34 -0600

asa gravatar image

updated 2016-04-04 11:08:38 -0600

Hi,

I am working with OpenCV image registration library "reg" under "opencv-contrib". I am using the MapAffine class to estimate affine motion. I need to modify the shift vector element (multiply it by a constant factor). I can get the linear transformation matrix and shift vector using getLinTr() and getShift(). Before doing the warping (using inverseWarp() ) I want to multiply the shift vector by a constant. This is what I have done so far: (Following this tutorial (https://github.com/Itseez/opencv_cont...)

Ptr<Map> mapPtr;
MapperGradAffine mapper;
MapperPyramid mapPyr(mapper);
Ptr<Map> mapPtr;
mapPyr.calculate(image1, image2,  mapPtr);
MapAffine* mapAff = dynamic_cast<MapAffine*>(mapPtr.get());

Then doing the warping:

mapAff->inversewarp(image2, destination);

Now I want to modify the shift vector prior to doing the above step. I have tried to modify the shift part using opencv Mat obejcts:

cv::Mat lin_tr = Mat(mapAff->getLintr); //getting the linear part
cv::Mat shift = Mat(mapAff->getShift()); //getting the translation
cv::Mat* aff_mat;
cv::hconcat(lin_tr, 2 * shift, *aff_mat);

Now the affine matrix is in a Mat object. My question is how can I recast it to MapAffine so that I can use the inversewarp() function. Or is there another way to modify the mapAffine reference directly?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-04-06 12:10:05 -0600

asa gravatar image

I was able to solve the issue like this:

After

MapAffine* mapAff = dynamic_cast<MapAffine>(mapPtr.get);

I create a MapAffine object using the parameterised constructor where I multiply the shift component by the integer factor:

MapAffine mapAff2 = cv::reg::MapAffine(ampAff->getLinTr(), alpha * mapAff->getShift());
// alpha is the integer factor

Then I call inversewarp() using mapAff2:

mapAff2.inversewarp(source, destination);

If there's a more efficient way of doing it please let me know

Thanks

edit flag offensive delete link more

Comments

there is an efficient way of doing it. Use the scale() function

mapAff->scale(alpha)`//multiplies the shift vector by a factor`

somehow I missed this simple function!

asa gravatar imageasa ( 2016-04-07 17:07:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-04 11:06:34 -0600

Seen: 342 times

Last updated: Apr 06 '16