我想使用双三次插值来执行图像大小调整。然而,我的输出图像new_img看起来与我最初加载的图像img完全相同。此外,当我找到new_img的宽度和高度时,它与我的原始图像具有相同的尺寸。我以为应该调整目标图像的大小?这是我的密码。有人能看看我是否做了什么不准确的事吗?提前谢谢。
#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace std;
int main( int argc, char* argv ) {
IplImage* img = NULL;
const int maxScale = 1;
img = cvLoadImage("C:\walk mii.jpg");
if (!img){return -1;}
for(int s = 1; s <= maxScale; s++)
{
IplImage* new_img = img;
if( s > 1 ) {
new_img = cvCreateImage(cvSize(img->width*s,img->height*s), img->depth, img->nChannels );
cvResize( img, new_img, CV_INTER_CUBIC );}
cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
cvShowImage( "original", img);
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
cvShowImage( "result", new_img);
CvSize dim = cvGetSize(new_img);
cout <<" dimensions:: height:" << dim.height<<" width:"<< dim.width<< endl;
cvWaitKey(0);
cvReleaseImage( &img );
cvReleaseImage( &new_img );
cvDestroyWindow( "result" );
return 0;
}
}
更改代码:
#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace std;
int main( int argc, char* argv ) {
IplImage* img = NULL;
IplImage* new_img = NULL;
img = cvLoadImage("C:\walk mii.jpg");
if (!img){
return -1;}
new_img = cvCreateImage(cvSize(img->width,img->height), img->depth, img->nChannels );
cvResize( img, new_img, CV_INTER_CUBIC );
cvNamedWindow( "original", CV_WINDOW_AUTOSIZE );
cvShowImage( "original", img);
cvNamedWindow( "result", CV_WINDOW_AUTOSIZE );
cvShowImage( "result", new_img);
CvSize dim = cvGetSize(new_img);
cout <<" dimensions:: height:" << dim.height<<" width:"<< dim.width<< endl;
cvWaitKey(0);
cvReleaseImage( &img );
cvReleaseImage( &new_img );
cvDestroyWindow( "result" );
return 0;
}
IplImage* new_img = img;
执行浅拷贝,因此new_img和img指向相同的数据
您需要放大。。你有两种方式(只显示高度比例):
1)
Mat testIn(inputRows, inputCols, CV_32F);
Mat testOut(inputRows*2, inputCols, CV_32F);
Size sz = testOut.size();
resize(testIn, testOut, sz, 0.0f, 0.0f, INTER_CUBIC);
因此openCV使用"sz"(例如:"Y"因子为sz.height/testIn.height)自动计算testIn与testOut之间的比率
2)
Mat testIn(inputRows, inputCols, CV_32F);
Mat testOut(inputRows*2, inputCols, CV_32F);
Size sz = testOut.size();
resize(testIn, testOut, sz, 2.0f, 0.0f, INTER_CUBIC);
因此openCV使用"2.0f"参数作为比率(对于"Y"),但在这里您必须确保testOut有足够的大小用于这样的比率