Opencv Warpperspective

OpenCV warpPerspective with another datatype

It's not warpPerspective that doesn't want to take this datatype. It's OpenCV in general, since arrays of unsigned 32bit integers are not supported.

You can have:

  • 8 bit integers, signed and unsigned
  • 16 bit integers, signed and unsigned
  • 32 bit integers, signed only
  • 32 bit floats
  • 64 bit floats

The numpy library's arrays (which are used by the Python API) are somewhat more flexible in what they can do. Unfortunately this can sometime lead to fairly obscure errors when they're passed to OpenCV functions.


Unfortunately for you, using 32bit signed integers is also out of question, because cv::remap (which is used to perform the actual transformation) doesn't seem to support them. It does, however, support all the other 6 available types. Depending on the actual range of your depthmap values, either the 16 bit integers, or one of the floating point options will do.

Set background of Python OpenCV warpPerspective

If you look at the documentation for the warpPerspective function from the online OpenCV documentation (http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html) says that there is a parameter you can give to the function to specify the constant border color:

cv2.warpPerspective(src, M, dsize[, dst[, flags[, borderMode[, borderValue]]]])

where

src – input image.
dst – output image that has the size dsize and the same type as src .
M – 3\times 3 transformation matrix.
dsize – size of the output image.
flags – combination of interpolation methods (INTER_LINEAR or INTER_NEAREST) and the optional flag WARP_INVERSE_MAP, that sets M as the inverse transformation ( \texttt{dst}\rightarrow\texttt{src} ).
borderMode – pixel extrapolation method (BORDER_CONSTANT or BORDER_REPLICATE).
borderValue – value used in case of a constant border; by default, it equals 0.

So something like:

cv2.warpPerspective(dist, M, (width, height), cv2.INTER_LINEAR, cv2.BORDER_CONSTANT, 255)

Should change the border to a constant white color.



Related Topics



Leave a reply



Submit