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()”
我找了很多方法,但似乎都不管用?
发布于 2013-01-03 23:42:30
这是一个简单的函数,可以将任何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-04 02:53:54
将opencv中的任何灰度8位或16位单元图像转换为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);希望这是一种简单的方式。
https://stackoverflow.com/questions/14141752
复制相似问题