Is there any function in the OpenCV python wrapper that does the same thing as Mat's convertTo method in OpenCV 2?
I basically want to call this function in python
out.convertTo( out, CV_32F, 1.0/255, 0 );
where out is a grayscale image.
I have already made use of cv.ConvertScale by keeping my dst argument as type CV_32FC1, but I am trying to keep my python code as cv2 conformant as possible. Any clues?
In OpenCV the main matrix class is called Mat and is contained in the OpenCV-namespace cv. This matrix is not templated but nevertheless can contain different data types. These are indicated by a certain type-number. Additionally, OpenCV provides a templated class called Mat_, which is derived from Mat.
Creates a matrix header and allocates the matrix data. Python: cv. CreateMat(rows, cols, type) → mat Parameters: rows – Number of rows in the matrix cols – Number of columns in the matrix type – The type of the matrix elements in the form CV_<bit depth><S|U|F>C<number of channels> , where S=signed, U=unsigned, F=float.
The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc. This class comprises of two data parts: the header and a pointer.
imread() method loads an image from the specified file. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format) then this method returns an empty matrix. Parameters: path: A string representing the path of the image to be read.
You can simply use Numpy functions for this.
eg :
res = np.float32(out)
scaling, you will have to do separately:
res = res*scaling_factor
If you are not trying to convert the data type, use this:
cv2.convertScaleAbs(image, result, alpha, beta)
where alpha is you scale factor and beta is a shift value. More details in the OpenCV docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With