Question

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

Was it helpful?

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

OTHER TIPS

If you are not bound to use the old-style OpenCV structures, I suggest switching to the more intuitive way of handling images in the newer versions : [ cv::Mat ] and I/O: [ cv:imread / cv:imwrite ] Give it a read: http://opencv.willowgarage.com/documentation/cpp/basic_structures.html http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html

cvSaveImage can only save 8 bit images.

You are trying to save a 32 bit float image as a jpeg, but jpeg only supports 8 bit (ok the standard has 12 bit but nobody supports that).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top