首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

【大神】OpenCV图像旋转如何图像会扭曲那

2013-01-04 
【求助大神】OpenCV图像旋转怎么图像会扭曲那?以下就是我的代码了,width,height,channels,depth均是原图像的

【求助大神】OpenCV图像旋转怎么图像会扭曲那?
以下就是我的代码了,width,height,channels,depth均是原图像的,dataSource是 (uchar *)pImgSource->imageData;~~
感觉程序没啥问题啊,但是得到的结果很奇怪
这个是旋转60度的【大神】OpenCV图像旋转如何图像会扭曲那
这个是旋转1度的【大神】OpenCV图像旋转如何图像会扭曲那

求指点!!感激不尽


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];
}
}
}

[解决办法]
每行像素数和每行字节数不一样,每行字节数可能为了对齐32字节而大于每行像素数。

热点排行