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

后端 未结 6 1049
我寻月下人不归
我寻月下人不归 2020-12-06 06:25

I need to convert an 8-bit IplImage to a 32-bits IplImage. Using documentation from all over the web I\'ve tried the following things:

// general code
img2 =         


        
6条回答
  •  广开言路
    2020-12-06 06:32

    The function you are looking for is cvConvertScale(). It automagically does any type conversion for you. You just have to specify that you want to scale by a factor of 1/255 (which maps the range [0...255] to [0...1]).

    Example:

    IplImage *im8 = cvLoadImage(argv[1]);
    IplImage *im32 = cvCreateImage(cvSize(im8->width, im8->height), 32, 3);
    
    cvConvertScale(im8, im32, 1/255.);
    

    Note the dot in 1/255. - to force a double division. Without it you get a scale of 0.

提交回复
热议问题