Reading RGB jp2 image results in Red and Blue channels reversed
I'm using OpenCV 3.1.0 I'm calling it from Java.
When I read a jp2 file that was created using ImageIO I get an image with the red and blue channels reversed. When I open it using ImageIO ( https://github.com/jai-imageio/jai-im... ), it's fine. Is the opencv codec that loads the jp2 simply assuming the pixels are packed BGR rather than checking the relevant metadata?
I can fix this on a case by case basis by rewriting all of the images in memory before I do anything with them but this seems like a bug and I'd need to do it on an ad-hoc basis.
Thanks Jim
The default color order in memory of OpenCV is BGR: http://docs.opencv.org/3.1.0/db/da5/tutorial_how_to_scan_images.html.
You can test it by loading jpeg, png, ... images.
I think if you set the flag IMREAD_ANYCOLOR it will check the metadata.
Thanks for the suggestions. I was pretty sure using the flag would work but unfortunately it didn't. If I write the image with OpenCV it works but if I had previously written it out it doesn't read it in correctly. I suppose it's possible the image is actually wrong but it reads in fine with ImageIO.
Well, if you do need to switch it, the best optimized way is to use cvtColor with the COLOR_RGB2BGR flag. I don't know how to check if it's switched except by manually.