Image rotate opecv error
Posted
by avd
on Stack Overflow
See other posts from Stack Overflow
or by avd
Published on 2010-05-20T06:02:07Z
Indexed on
2010/05/20
6:10 UTC
Read the original article
Hit count: 195
When I use this code to rotate the image, the destination image size remains same and hence the image gets clipped. Please provide me a way/code snippet to resize accordingly (like matlab does in imrotate) so that image does not get clipped and outlier pixels gets filled with all white instead of black.
void imrotate(std::string imgPath,std::string angleStr,std::string outPath) {
size_t found1,found2;
found1=imgPath.find_last_of('/');
found2=imgPath.size()-4;
IplImage* src=cvLoadImage(imgPath.c_str(), -1);;
IplImage* dst;
dst = cvCloneImage( src );
int angle = atoi(angleStr.c_str());
CvMat* rot_mat = cvCreateMat(2,3,CV_32FC1);
CvPoint2D32f center = cvPoint2D32f(
src->width/2,
src->height/2
);
double scale = 1;
cv2DRotationMatrix( center, angle, scale, rot_mat );
cvWarpAffine( src, dst, rot_mat);
char angStr[4];
sprintf(angStr,"%d",angle);
cvSaveImage(string(outPath+imgPath.substr(found1+1,found2-found1-1)+"_"+angStr+".jpg").c_str(),dst);
cvReleaseImage(&src);
cvReleaseImage(&dst);
cvReleaseMat( &rot_mat );
}
Original Image:
Rotated Image:
© Stack Overflow or respective owner