Home > Software engineering >  How to convert individual x y maps to 2-channel matrix map in OpenCV?
How to convert individual x y maps to 2-channel matrix map in OpenCV?

Time:06-15

I am trying to do forward mapping with OpenCV, but remap() only allows inverse mapping so I need to inverse the map(s) before using them. This is the inverse map method I want to use and it only takes in a single 2 channel map.

In the convert maps docs it says that you can convert one 2 channel (x,y) map into individual x and y maps. It also says that you can do "Reverse conversion". Does this mean you can convert from x and y maps to a single (x,y) map shape?

CodePudding user response:

import cv2 as cv

(xymap, _) = cv.convertMaps(map1=xmap, map2=ymap, dstmap1type=cv.CV_32FC2)

Documentation isn't terribly obvious. The bulleted list has a third bullet, which says "Reverse conversion". You can use dstmap1type=cv.CV_32FC2.

Or simply use numpy:

xymap = np.dstack([xmap, ymap])

You are working with v2.x documentation... don't. Use current docs. You are very surely not using OpenCV v2.x.

  • Related