Reputation: 662
I have code in C++ for converting an image to "CV_32FC1" but I want to do same thing in Python. Here is my C++ code.
img.convertTo(img, CV_32FC1);
How can I do same thing in Python?
Upvotes: 2
Views: 5153
Reputation: 67
You can use the function
cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Upvotes: -1
Reputation: 22954
Python uses numpy
to manage the image pixel data, you can do something like this in numpy to change the data type of a matrix:
img = img.astype("float32")
As added by @HansHirse in the comments, this operation will just change the data type of the matrix, but if you want to change the scale of pixel values then you should use img = img.astype("float32")/255
, to convert all the pixel values in range 0.0 - 1.0
Upvotes: 4