How to convert image from CV_8UC1 to CV_32FC1 in opencv?
I read an image which type is CV_8UC1 and I want to convert it to CV_32FC1.but when I use the convertTO () function my image becomes completely white and I don't know why!
Mat Image(512,512,CV_32FC1);
Image = imread("C:\\MGC.jpg",CV_LOAD_IMAGE_GRAYSCALE);
/// show image
namedWindow("pic");
int x = 0; int y = 0;
imshow("pic", Image);
cout<<Image.type()<<endl;
Image.convertTo(Image,CV_32FC1);
cout<<Image.type()<<endl;
////show converted image
namedWindow("pic1");
imshow("pic1",Image );
+4
source to share
3 answers
The methods used by Andrew doesn't seem to exist in the current (v3.4) opencv for python. Here is an alternative solution that uses scikit image
http://scikit-image.org/docs/dev/user_guide/data_types.html
import cv2
from skimage import img_as_float
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
image1 = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
image2 = img_as_float(image1)
cv2.imshow('IMAGE1',image1)
cv2.imshow('IMAGE2', image2)
while(1):
k = cv2.waitKey(100) & 0xff
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
0
source to share