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.