OpenCV - cvtColor does not change colorspace, it changes colors
<p>I am trying to make an object tracker using OpenCV 3.1.0 and C++ following this Python example: <a href="http://docs.opencv.org/3.1.0/df/d9d/tutorial_py_colorspaces.html#gsc.tab=0" rel="nofollow noreferrer">http://docs.opencv.org/3.1.0/df/d9d/tutorial_py_colorspaces.html#gsc.tab=0</a>.</p>

<p>I have some problems with cvtColor() function, because it changes the colors of my images and not its colorspace. I have this code:</p>

<pre><code>Mat original_image;
original_image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // The image is passed as arg
if (!original_image.data)
{
    printf("Problem!\n");
    return -1;
}

// From BGR to HSV
Mat hsv_image(original_image.rows, original_image.cols, original_image.type());
cvtColor(original_image, hsv_image, CV_BGR2HSV);
imwrite("hsv_image.png", hsv_image);
</code></pre>

<p>original_image is a CV_8UC3, compatible with cvtColor() and should be originally in BGR colorspace.</p>

<p>I made the test image below with GIMP:</p>

<p><a href="https://i.stack.imgur.com/8CzKb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8CzKb.png" alt="Test image"></a></p>

<p>And I get this image as result:</p>

<p><a href="https://i.stack.imgur.com/bks8V.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bks8V.png" alt="HSV image - result"></a></p>

<p>I decided to try the conversion from BGR to RGB, changing BGR2HSV to BGR2RGB, and with the same test image, I get this result</p>

<p><a href="https://i.stack.imgur.com/Izsqq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Izsqq.png" alt="RGB image - result"></a></p>

<p>Here, it's more clear that the channels of the image are changed directly...</p>

<p>Has anybody any idea about what's happening here?</p>