lucasw / rviz_camera_stream

Custom rviz camera plugin that published rendered camera video stream
BSD 3-Clause "New" or "Revised" License
59 stars 47 forks source link

Red and blue channels swapped in image #20

Closed johnwason closed 6 years ago

johnwason commented 6 years ago

The images published from rviz have the red and blue channels swapped. Most likely there is an inconsistency in the RGB byte order.

johnwason commented 6 years ago

Setting line 127 of camera_display.cpp to a static pixel format seems to fix the problem:

Ogre::PixelFormat pf = Ogre::PF_B8G8R8;

johnwason commented 6 years ago

Using the Ogre:PF_BYTE_RGB is a better option. It is machine independent endian.

Ogre::PixelFormat pf = Ogre::PF_BYTE_RGB;

lucasw commented 6 years ago

I've been sloppy with branches here- 1c409a5ff9ca4cd775e9846306ec4923a8a73df8 is likely a fix but I've only applied it in the librviz_node branch (the intent of that branch is an experiment that probably belongs in a standalone repo).

lucasw commented 6 years ago

I cherry picked 1c409a5 to 02b6410647c1fbc043bd889a72303aad932841d1- pull and see if that works for you.

johnwason commented 6 years ago

Based on the Ogre user manual, PF_B8G8R8 and friends use the local machine endian, while PF_BYTE_RGB and friends always use "standard" endian. (I forget if BGR or RGB is "standard" endian for binary data.)

Taken from OgrePixelFormat.h

#if OGRE_ENDIAN == OGRE_ENDIAN_BIG
        /// 3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue
        PF_BYTE_RGB = PF_R8G8B8,
        /// 3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red
        PF_BYTE_BGR = PF_B8G8R8,
        /// 4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha
        PF_BYTE_BGRA = PF_B8G8R8A8,
        /// 4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
        PF_BYTE_RGBA = PF_R8G8B8A8,
#else
        /// 3 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue
        PF_BYTE_RGB = PF_B8G8R8,
        /// 3 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red
        PF_BYTE_BGR = PF_R8G8B8,
        /// 4 byte pixel format, 1 byte for blue, 1 byte for green, 1 byte for red and one byte for alpha
        PF_BYTE_BGRA = PF_A8R8G8B8,
        /// 4 byte pixel format, 1 byte for red, 1 byte for green, 1 byte for blue, and one byte for alpha
        PF_BYTE_RGBA = PF_A8B8G8R8,
#endif

Based on this, you should probably be using the PFBYTE* pixel formats. The inconsistency explains why the channels are being flipped.

lucasw commented 6 years ago

Closing with above commit 00b20d7

lucasw commented 6 years ago

The computer I'm on now has PF_X8R8G8B8 (26) as the suggested pixel format.