Domanda

When i convert a image to YUV from RGB I cant get a value of Y when I try printing the pixels. I get a value 377 and when I cast it with integer I get 255. WHich I presume is incorrect. Is there a better way or rather correct way to print the values of YUV image pixels.

Actually i am priting the values (int)src.at<Vec3b>(j,i).val[0]= 255 and src.at<Vec3b>(j,i).val[0] = 377

Also on that note, the Y is the combination of RGB calculated with some constants according to note. I am actually confused as how to get the value of Y.

È stato utile?

Soluzione

This is a problem of OpenCV. OpenCV does not gracefully handle (scale) YUV or HSV color spaces for uchar format. With Vec3b you have effectively 3-channel uchar, and that ranges [0;255].

The solution is to use another matrix type. With cv::Mat3f you have a 3-channel floating point image. Then the values will be correctly converted by cvtColor function. You can get a Mat3f from a Mat3b by assignment.

Another solution that uses less memory may be Mat3s and Mat3w types, if supported by cvtColor.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top