(Yuriy asked this in the post on my site.)
Why doesn't cvMatToQImage's CV_8UC4 case swap red and blue channels? #1
This has to do with endianness.
Although not totally clear from the docs, some of QImage's formats we use here are endian-dependent. So, for example:
Little Endian
- QImage::Format_ARGB32 the bytes are ordered: B G R A
- QImage::Format_RGB32 the bytes are ordered: B G R (255)
- QImage::Format_RGB888 the bytes are ordered: R G B
Big Endian
- QImage::Format_ARGB32 the bytes are ordered: A R G B
- QImage::Format_RGB32 the bytes are ordered: (255) R G B
- QImage::Format_RGB888 the bytes are ordered: R G B
Notice that Format_RGB888 is the same regardless of endianness. Since OpenCV expects (B G R) we need to swap the channels for this format.
This is why some conversions here swap the red and blue channels and others do not.
This code assumes little endian. It would be possible to add conversions for big endian machines though. If you are using such a machine, please feel free to submit a pull request here.
I'll add some comments to the header to make this clear.
No due date set.
No dependencies set.
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?