2
char* filename1="1.bmp";  
IplImage* greyLeftImg= cvLoadImage(filename1,0);
char* filename2="2.bmp";
IplImage* greyRightImg= cvLoadImage(filename2,0); 

IplImage* greyLeftImg32=cvCreateImage(cvSize(width,height),32,greyLeftImg->nChannels);//IPL_DEPTH_32F 
IplImage* greyRightImg32=cvCreateImage(cvSize(width,height),32,greyRightImg->nChannels);

总是失败,说“未知函数中的断言失败(src.size == dst.size && dst.type() == CV_8UC(src.channels()))”

我已经搜索了很多方法,但它们似乎都不起作用?

4

2 回答 2

2

将opencv中的任何灰度8位或16位uint图像转换为32位浮点类型的简单步骤是这样的......

IplImage* img = cvLoadImage( "E:\\Work_DataBase\\earth.jpg",0);
IplImage* out = cvCreateImage( cvGetSize(img), IPL_DEPTH_32F, img->nChannels);

double min,max;

cvMinMaxLoc(img,&min,&max);

// Remember values of the floating point image are in the range of 0 to 1, which u 
// can't visualize by cvShowImage().......
cvCvtScale(img,out,1/ max,0);

希望这是简单的方法...

于 2013-01-03T18:53:54.323 回答
1

IplImage这是一个将任何转换为​​ 32 位浮点数的简单函数。

IplImage* convert_to_float32(IplImage* img)
{
    IplImage* img32f = cvCreateImage(cvGetSize(img),IPL_DEPTH_32F,img->nChannels);

    for(int i=0; i<img->height; i++)
    {
        for(int j=0; j<img->width; j++)
        {
            cvSet2D(img32f,i,j,cvGet2D(img,i,j));
        }
    }
    return img32f;
}

一个重要的考虑是,对于 OpenCV 中的浮点图像,只有那些像素值介于 0.0 和 1.0 之间的图像才能被可视化。要可视化浮点图像,您必须将值从 0.0 缩放到 1.0。

以下是如何执行此操作的示例:

IplImage* img8u = cvLoadImage(filename1,0);

IplImage* img32f = convert_to_float32(img8u);

cvShowImage("float image",img32f); //Image will not be shown correctly
cvWaitKey(0);

cvScale(img32f, img32f, 1.0/255.0);

cvShowImage("float image normalized",img32f); //Image will be shown correctly now 
cvWaitKey(0);
于 2013-01-03T15:42:29.873 回答