【求助大神】OpenCV图像旋转怎么图像会扭曲那?
以下就是我的代码了,width,height,channels,depth均是原图像的,dataSource是 (uchar *)pImgSource->imageData;~~
感觉程序没啥问题啊,但是得到的结果很奇怪
这个是旋转60度的
这个是旋转1度的
求指点!!感激不尽
void Operation::rotate(double angle,int method)
{
angle = angle / 180.0 * 3.141592653;
int width2=(int)(abs(width*cos(angle))+abs(height*sin(angle)));
int height2=(int)(abs(width*sin(angle))+abs(height*cos(angle)));
img = cvCreateImage(cvSize(width2, height2), depth,channels);
uchar* dataDestination = (uchar*)img->imageData;
for(int y2=0;y2<height2;y2++)
{
for(int x2=0;x2<width2;x2++)
{
double y2_coor = y2-height2/2.0;
double x2_coor = x2-width2/2.0;
double x1_coor=(x2_coor)*cos(-angle)+(y2_coor)*sin(-angle);
double y1_coor =-(x2_coor)*sin(-angle)+(y2_coor)*cos(-angle) ;
double ori_x = x1_coor + width/2.0;
double ori_y = height/2.0 + y1_coor;
if (x2==250&&y2==128)
printf("");
if(ori_x < 0||ori_x > width-1||ori_y < 0||ori_y > height-1)
continue;
int x=(int)(ori_x+0.5);
int y=(int)(ori_y+0.5);
//printf("(%d,%d)-> <%.2f,%.2f> -- <%.2f,%.2f> --> (%d,%d)\n", x2,y2,x2_coor,y2_coor,x1_coor,y1_coor,x,y);
dataDestination[y2*width2+x2]=dataSource[y*width+x];
}
}
}