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
Some Clarification Needed About Synchronous Versus Asynchronous Asio Operations
Difference Between Logical and Physical Const-Ness
What Is the Size of an Enum Type Data in C++
C++11 Anonymous Union with Non-Trivial Members
Qtcpsocket: Reading and Writing
How to Build Boost 1.64 in 64 Bits
Compile Openmp Programs with Gcc Compiler on Os X Yosemite
Shared_From_This Causing Bad_Weak_Ptr
Convert a C++ Program to a Windows Service
Edges on Polygon Outlines Not Always Correct
Implicit VS Explicit Conversion
Making a C++ Class a Monitor (In the Concurrent Sense)
C++ Trying to Swap Values in a Vector
Boost-Python How to Pass a C++ Class Instance to a Python Class
What Is the Safe Way to Fill Multidimensional Array Using Std::Fill
How to Call Memcpy() and Memmove() with "Number of Bytes" Set to Zero
Is There a C++ Iterator That Can Iterate Over a File Line by Line