Do you display images using imshow() ?
imshow() does not actually know the color space, but will print images as BGR , even if you convert them to a different format. This is why you get weird results.
To convince yourself, try converting the image from RGB to BGR and print it with imshow() , then do the same by switching from BGR to RGB:
cv::cvtColor(src, dst, CV_RGB2BGR); imshow("RGB2BGR", dst); cv::cvtColor(src, dst, CV_BGR2RGB); imshow("BGR2RGB", dst);
Then your example proves that converting the BGR image to HSV will not result in the same matrix as converting the RGB image to HSV.
Jonesv
source share