You are dealing with an 8 bit image (3-channel the way you load it, without any flags), which means that for each channel your values are in the range [0, 255]. So even though you assign a float
value, you can only have uchar
and thus your 0.1415 becomes 0.
If you had a float CvMat
, then you could assign float
values. For example:
CvMat* matrix = cvCreateMat(10, 10, CV_32F);
CvScalar scalar(0.1415, 0, 0, 0);
cvSet2D(matrix, 5, 5, scalar);
double pixelValue = cvGet2D(matrix, 5, 5).val[0]; // Now pixelValue = 0.1415
If you want to work with float
images, check this question and this post.