opencv uses BGR by default!
stackoverflow. The cv::imwrite() function correctly writes an image file if the input cv::Matis in BGR order (which is the case if you let OpenCV create it). If you created the image by yourself, you have to convert the color ordering before, for example by calling as suggested by bamboove cv::cvtColor(in, out, CV_RGB2BGR); if you created an RGB image.
Compile without dependency on GTK etc
cmake -D SOFTFP=ON -D BUILD_SHARED_LIBS=OFF -D CMAKE_BUILD_TYPE=DEBUG -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D OPENCV_BUILD_3RDPARTY_LIBS=ON -D WITH_FFMPEG=ON -D WITH_GTK=ON -D WITH_OPENEXR=ON -D WITH_OPENNI=ON -D WITH_PNG=ON -D WITH_TBB=ON -D WITH_XINE=ON -D WITH_GSTREAMER=ON .