cvSaveImage()这个第一个参数,我用的是绝对路径才能正确的保存修改后的图片
#include <opencv/cxcore.h>
#include <opencv/highgui.h>
#include <opencv2\opencv.hpp>
#include <iostream>
#include <cstdlib>
using namespace std;
#pragma comment(lib, "opencv_core242d.lib")
#pragma comment(lib, "opencv_highgui242d.lib")
#pragma comment(lib, "opencv_objdetect242d.lib")
#pragma comment(lib, "opencv_imgproc242d.lib")
void scaleImage(IplImage* srcimg,IplImage* &tarimg,int width,int height);
// width,hight分别对应argv[3],argv[4]
int main(int argc,char* argv[])
{
IplImage* image = NULL;
image = cvLoadImage(argv[1]);
IplImage* newImage=NULL;
int newWidth = atoi(argv[3]);
int newHeight = atoi(argv[4]);
scaleImage(image,newImage,newWidth,newHeight);
cvNamedWindow("windows");
cvShowImage("windows",image);
// 64 * 128
cvWaitKey();
cvSaveImage(argv[2],newImage,0);
cvDestroyWindow("windows");
cvReleaseImage(&image);
return 0;
}
void scaleImage(IplImage* srcimg,IplImage* &tarimg,int width,int height)
{
CvSize tarimg_cvsize;
tarimg_cvsize.width=width;
tarimg_cvsize.height=height;
tarimg = cvCreateImage( tarimg_cvsize,srcimg->depth,srcimg->nChannels);
cvResize(srcimg,tarimg,CV_INTER_LINEAR);
}