调整图像大小和显示图像
我正在尝试调整图像大小,然后显示它以检查它是否已调整大小。
#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 错误:断言失败==dst.type>>>未知功能 文件 c:\slave\winInstallerMegaPack\src\opencv\modules\imgproc\src\imgwarp.cpp 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;
请解释一下。
I am trying to resize an image and then display it to check whether it has been resized or not.
#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;
}
But it produces an error
OpenCV Error:Assertion failed==dst.type<>> in unknown function
file c:\slave\winInstallerMegaPack\src\opencv\modules\imgproc\src\imgwarp.cpp
line 3210.
Please point what am i doing wrong and suggest some way to overcome it.
On the other hand other code works fine.
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;
Please explain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是第一个还是第二个代码示例?
如果您使用第一个,我想您的“tmpsize”应该具有与源文件相同的通道数。
Are you using the first or the second code example?
If you're using the first one, I guess your "tmpsize" should have the same number of channels as your source file.
在第一个示例中,您为通道数写入 0
所以改变
IplImage* tmpsize=cvCreateImage(大小,8,0);
线
IplImage* tmpsize=cvCreateImage(大小,ipl->深度, ipl->nChannels);
in the first example you write 0 for number of channels
so change
IplImage* tmpsize=cvCreateImage(size,8,0);
line
IplImage* tmpsize=cvCreateImage(size,ipl->depth, ipl->nChannels );