opencv 旋转图片
2012-03-31 14:36
267 查看
没什么好说的,直接上代码
旋转 参数: angle 旋转的角度 clockwise = false 逆时针旋转 = true 顺时针旋转 */ // clockwise 为true则顺时针旋转,否则为逆时针旋转 IplImage* CPreprocessImage::rotateImage(const IplImage* src, int angle, bool clockwise) { angle = abs(angle) % 180; if (angle > 90) { angle = 90 - (angle % 90); } IplImage* dst = NULL; int width = (double)(src->height * sin(angle * CV_PI / 180.0)) + (double)(src->width * cos(angle * CV_PI / 180.0 )) + 1; int height = (double)(src->height * cos(angle * CV_PI / 180.0)) + (double)(src->width * sin(angle * CV_PI / 180.0 )) + 1; int tempLength = sqrt(double(src->width * src->width + src->height * src->height)) + 10; int tempX = (tempLength + 1) / 2 - src->width / 2; int tempY = (tempLength + 1) / 2 - src->height / 2; int flag = -1; dst = cvCreateImage(cvSize(width, height), src->depth, src->nChannels); cvZero(dst); IplImage* temp = cvCreateImage(cvSize(tempLength, tempLength), src->depth, src->nChannels); cvZero(temp); cvSetImageROI(temp, cvRect(tempX, tempY, src->width, src->height)); cvCopy(src, temp, NULL); cvResetImageROI(temp); if (clockwise) flag = 1; float m[6]; int w = temp->width; int h = temp->height; m[0] = (float) cos(flag * angle * CV_PI / 180.); m[1] = (float) sin(flag * angle * CV_PI / 180.); m[3] = -m[1]; m[4] = m[0]; // 将旋转中心移至图像中间 m[2] = w * 0.5f; m[5] = h * 0.5f; // CvMat M = cvMat(2, 3, CV_32F, m); cvGetQuadrangleSubPix(temp, dst, &M); cvReleaseImage(&temp); return dst; }
相关文章推荐
- opencv 旋转图片
- [IOS OpenCV]摄像头采集图片用 CreateIplImageFromUIImage 转换后图像被旋转、变形解决方案
- 【图像处理】基于OpenCV底层实现的图片旋转
- 使用opencv提取单据轮廓并旋转后生成图片
- opencv 图像旋转的问题 ,图片大小不变,怎么把图片移到中间去,图片跟框框想切
- python+opencv图片旋转矩形分割
- OpenCV实现图片旋转
- openCV——人脸检测资料汇总(附录)用PhotoShop尝试旋转图片
- python opencv对图像进行旋转且不裁剪图片的方法
- OpenCV两张图片叠加,一张旋转一定的角度,另一张不变,如何叠加?
- OpenCV Mat结构的图片 旋转顺时针90度 180度 270度 逆时针90度
- OpenCV2.4.13中warpAffine函数理解,旋转,仿射变换,缩放,保持完整图片
- opencv 图片旋转
- opencv 图片旋转
- opencv图片旋转后图片无法填满窗口有黑边解决方法
- 【OpenCV】通过旋转图片增加训练集
- opencv图片旋转180度
- opencv图片旋转90度,180度,270度
- PNG透明图片叠加(Opencv实现,包括旋转缩放以及边界处理)
- opencv 图片旋转90度