1

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

Community
  • 1
  • 1
Pixel
  • 121
  • 2
  • 19

3 Answers3

2

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

Coke Head
  • 133
  • 4
  • While I agree whole heartedly with the advice, this doesn't address the actual problem at all! -1 for giving a link to a very old version of the documentation - use http://docs.opencv.org/2.4.5/modules/core/doc/basic_structures.html – Bull May 23 '13 at 10:13
  • thank you for pointing to the latest doc. however, I tend to believe that reading about cv::Mat in the original doc is very relevant (i.e. to see full list of methods). – Coke Head Jun 03 '13 at 15:22
2

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);
}
Coke Head
  • 133
  • 4
1

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).

Bull
  • 11,771
  • 9
  • 42
  • 53
  • Then how to Save 32 bit Image ? – Pixel May 23 '13 at 07:16
  • IS it possible to convert Gray image to color Image ( 24 bit ) ? – Pixel May 23 '13 at 07:19
  • I have used YAML format (see cv::FileStorage). Make it seem to cvSaveImage that our image has 4 times as big - I just repack each 4 byte pixel into 4x 1 byte images. I am not sure how to do this with an IplImage as I normally use a Mat (much easier to use) – Bull May 23 '13 at 07:23
  • 1
    cvCvtColor(grayImage, colorImage, CV_GRAY2BGR) will convert Gray image to color Image ( 24 bit ) – Bull May 23 '13 at 07:31