In the case you are stuck on the old OpenCV here is a more complete answer:
- 8 bit image - 1 color channel
- 24 bit image - 3 color channels (Blue, Green, Red)
- 32 bit image - 4 color channels (BGR + Alpha - very common in PNGs)
As I can see, Pixel, you are operating on JPEGs which means, you will need to handle either 8 bit (Grayscale) or 24 bit (BGR) input.
Here is the code you need:
if (inputImage->nChannels == 1)
{
cvCvtColor(inputImage, image24bit, CV_GRAY2BGR);
}
else
{
cvCopy(inputImage, image24bit, NULL);
}