NV12 图像数据的旋转
来源:互联网 发布:应用数学就业前景知乎 编辑:程序博客网 时间:2024/06/05 18:35
/img 原始数据destImg 目的数据m_width 原始数据的宽,旋转后可能改变m_height 原始数据的高m_cammer 0 前置摄像头 1 后置摄像头m_angle 角度看程序决定图像右旋还是左旋还有镜像/static int imgRotationNew(unsigned char *img, unsigned char *destImg, int * m_width, int * m_height, int m_cammer, int m_angle){ int width = *m_width; int height = *m_height; unsigned char * srcImagUV = (unsigned char *)((int)img + height * width); unsigned char * destImgUV = (unsigned char *)((int)destImg + width * height); int dx = 0; int dy = 0; if (0 == m_cammer) { // 图像矩阵需要向右旋转90度 if (0 == m_angle) { //img.resize(width, height); *m_width = height; *m_height = width; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { dx = height - 1 - i; dy = j; //img(dy, dx) = dest(i, j); destImg[dy*height + dx] = img[i*width + j]; destImgUV[((dy / 2) * (height / 2) + (dx / 2)) * 2 + 0] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 0]; destImgUV[((dy / 2) * (height / 2) + (dx / 2)) * 2 + 1] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 1]; } } } // 不用旋转 else if (90 == m_angle) { memcpy(destImg, img, width * height * sizeof(unsigned char) * 3 / 2); } // 旋转180度 else if (270 == m_angle) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { dx = width - 1 - j; dy = height - 1 - i; //img(dy, dx) = dest(i, j); destImg[dy*width + dx] = img[i*width + j]; destImgUV[((dy / 2) * (width / 2) + (dx / 2)) * 2 + 0] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 0]; destImgUV[((dy / 2) * (width / 2) + (dx / 2)) * 2 + 1] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 1]; } } } // 不做处理,任其错误 else if (180 == m_angle) { memcpy(destImg, img, width * height * sizeof(unsigned char) * 3 / 2); } } else if (1 == m_cammer) // 前置摄像头 { // 左旋90度,左右镜像 if (0 == m_angle) { *m_width = height; *m_height = width; //img.resize(width, height); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { dx = height - 1 - i; dy = width - 1 - j; //img(dy, dx) = dest(i, j); destImg[dy*height + dx] = img[i*width + j]; destImgUV[((dy / 2) * (height / 2) + (dx / 2)) * 2 + 0] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 0]; destImgUV[((dy / 2) * (height / 2) + (dx / 2)) * 2 + 1] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 1]; } } } // 左右镜像 else if (90 == m_angle) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { dx = width - 1 - j; dy = i; //img(dy, dx) = dest(i, j); destImg[dy*width + dx] = img[i*width + j]; destImgUV[((dy / 2) * (width / 2) + (dx / 2)) * 2 + 0] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 0]; destImgUV[((dy / 2) * (width / 2) + (dx / 2)) * 2 + 1] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 1]; } } } // 上下镜像 else if (270 == m_angle) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { dx = j; dy = height - 1 - i; //img(dy, dx) = dest(i, j); destImg[dy*width + dx] = img[i*width + j]; destImgUV[((dy / 2) * (width / 2) + (dx / 2)) * 2 + 0] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 0]; destImgUV[((dy / 2) * (width / 2) + (dx / 2)) * 2 + 1] = srcImagUV[((i / 2) * (width / 2) + (j / 2)) * 2 + 1]; } } } // 不做处理 else if (180 == m_angle) { memcpy(destImg, img, width * height * sizeof(unsigned char) * 3 / 2); } } return 0;}
0 0
- NV12 图像数据的旋转
- nv12 图像的旋转
- NV12 图像数据的插值时候旋转
- NV12 图像的线性插值
- NV12 数据的抠图
- nv12视频数据的产生与播放
- 【图像处理与医学图像处理】NV12与YV12的区别
- 基于DSP的图像旋转算法数据调度策略
- 图像UIVIEW的旋转
- 图像的旋转 OpenCV
- 图像旋转的实现
- OpenCV图像的旋转
- 图像的旋转变换
- 图像的旋转
- 图像的旋转操作
- NV12 和 NV21的区别
- 设置nv12的矩形边框
- 图像旋转后的还原图像坐标
- 容器跨主机通信之NAT
- Laptops CodeForces
- 设置linux共享目录
- 解决Oracle 11g在用EXP导出时,空表不能导出
- 同步/异步,阻塞/非阻塞区别
- NV12 图像数据的旋转
- 2016年全面前端面试题总结
- Spring Security笔记
- width:100%和height:auto区别
- 日期转换错误
- Android 权限配置一览
- 算法笔记之动态规划(DP)
- Paho MQTT 嵌入式c客户端研究笔记 (二)
- 冒泡排序算法总结