Type issues
Hello,
Actually, I'm trying to sum images.
That is just a simple example, you're gonna understand my issue :
Mat src ;
Mat datasrc1 ;
src = imread("/home/jetson/Downloads/wd-wallhaven-r2g7rm.jpg", 0);
int size_reshape = src.cols * src.rows ;
datasrc1 = src.reshape(0,1) ;
unsigned char * A ;
unsigned char * B ;
float * E ;
A = datasrc1.data;
E = new float char[size_reshape];
for (int i = 0 ; i<size_reshape ; i++){
E[i] = (float)A[i] ;
}
cv::Mat Result(src.rows, src.cols, CV_16FC1, E) ;
imwrite("/home/jetson/Desktop/blabla.jpeg", Result) ;
The image that I write is unreadable. I don't want to do a simple conversion, that is a sample of my work. I need to sum several image in 16bit images, and divide. As I don't have to loose informations, I need to use float Mat.
Thank you for your help,
A float is 32-bits. JPEG most likely cannot handle floating point images.
Yes but 16_FC1 is in half precision. Am I wrong ?
You are pointing a
cv::Mat
header at 32-bit data and inpterpreting it as 16-bit. How is that going to produce sensible output? And btw, your code above will not compile.E = new float char[size_reshape];
?wrong about anything being float (of any depih) here for sure, this is NOT matlab. if you use
imread()
with ".jpg" - you get a CV_8U imageand no, you cannot imwrite() float data as jpg here