0

我正在尝试调整图像大小,然后显示它以检查它是否已调整大小。

#include"cv.h"
#include"highgui.h"
#include<iostream>
 using namespace cv;

 int main()
 {
     IplImage* ipl = cvLoadImage("test1.jpg");
     cvShowImage("original:",ipl);
     CvSize size = cvSize(128,128); 
    IplImage* tmpsize=cvCreateImage(size,8,0);   
    cvResize(ipl,tmpsize,CV_INTER_LINEAR);
    cvShowImage("new",tmpsize);

     waitKey(0);
     return 0;
 }

但它会产生错误 OpenCV Error:Assertion failed==dst.type<>> in unknown function file c:\slave\winInstallerMegaPack\src\opencv\modules\imgproc\src\imgwarp.cpp line 3210。请指出我是什么做错了,并提出一些方法来克服它。另一方面,其他代码工作正常。

 IplImage *source = cvLoadImage( "test1.jpg");
// Here we retrieve a percentage value to a integer
int percent =50;
// declare a destination IplImage object with correct size, depth and channels
      IplImage *destination = cvCreateImage
( cvSize((int)((source->width*percent)/100) , (int)((source->height*percent)/100) ),
                                     source->depth, source->nChannels );

//use cvResize to resize source to a destination image
cvResize(source, destination);

// save image with a name supplied with a second argument
      cvShowImage("new:",destination);
      waitKey(0);
return 0;

请解释。

4

2 回答 2

1

您使用的是第一个还是第二个代码示例?

如果您使用的是第一个,我猜您的“tmpsize”应该与源文件具有相同数量的通道。

于 2012-02-04T20:58:16.070 回答
0

在第一个示例中,您为通道数写入 0,因此更改 IplImage* tmpsize=cvCreateImage(size,8,0); 线 IplImage* tmpsize=cvCreateImage(size,ipl->depth, ipl->nChannels );

于 2012-02-05T08:05:50.090 回答