int image_resize(IplImage *img,float factor)
{
IplImage *tmp;
tmp = vCreateimage(cvSize(img->width*factor,img->height*factor),8,3);
cvResize(img,tmp,CV_INTER_NN);
cvReleaseImage(&img);
cvCopyImage(tmp,img);
cvReleaseImage(&tmp);
return 0;
}
//ROI
IplImage* src = cvLoadImage("image.bmp", 3);
CvRect rect = cvRect(240, 360, 160, 120);
cvSetImageROI( src, rect ); // Sets the region of interest
cvSaveImage("roi.bmp", src);
// rotate image
double xshift, yshift;
iplGetRotateShift(90.0,124.0, 10.0, &xshift, &yshift);
iplRotate(file_image, dstimg, 10.0, xshift, yshift,
IPL_INTER_LINEAR );
Here is another example to choose ROI:
#include "stdafx.h"
#include< stdio.h>
#include< stdlib.h>
#include< cv.h>
#include< highgui.h>
int main()
{
IplImage* sourceimg = cvLoadImage("lena.bmp", 3);
CvRect r=cvRect(0,0,512,512);
cvSetImageROI(sourceimg,r);
CvMat *sub=cvCreateMat(r.width,r.height,sourceimg->depth);
//get sub-image in variable sub
cvGetSubRect(sourceimg,sub,r);
//pass that sub variable to an IplImage (extract the sub image from sourceimg)
IplImage *res=cvGetImage(sub,sourceimg);
//to align correctly (vertical flip)
//res->origin=1;
cvNamedWindow("Image",1);
cvShowImage("Image",res);
cvWaitKey(0);
return 1;
}
No comments:
Post a Comment