Search code examples
c++visual-c++opencvimage-processingiplimage

Issues facing in Opencv cvConvertScale


This is very simple code, But don't know where it Went wrong,where i covert Image from 8 to 32

Same thread as like this

How to convert an 8-bit OpenCV IplImage* to a 32-bit IplImage*?

char * InputImagePath = "E:\\Inp\\lg1.jpg";
IplImage* ImageIn = cvLoadImage(InputImagePath,1);

IplImage *img32 = cvCreateImage(cvGetSize(ImageIn), 32 , 3);
cvConvertScale(ImageIn,img32,1/255.);

cvSaveImage("E:\\Inp\\zzout.jpg",img32);

Output : zzout.jpg is saved in my local hard disk but its empty ( blank image )

Please help me out from this.. fedup with this simple issue


Solution

  • 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);
    }