opencv学习笔记(五)镜像对称

  设图像的宽度为width,长度为height。(x,y)为变换后的坐标,(x0,y0)为原图像的坐标。

水平镜像变换:

  

  代码实现:

  

 #include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;
using namespace cv; void hMirrorTrans(const Mat &src, Mat &dst)
{
CV_Assert(src.depth() == CV_8U);
dst.create(src.rows, src.cols, src.type()); int rows = src.rows;
int cols = src.cols; switch (src.channels())
{
case :
const uchar *origal;
uchar *p;
for (int i = ; i < rows; i++){
origal = src.ptr<uchar>(i);//ptr<>函数得到一行的指针,并用[]操作符访问某一列的像素值
p = dst.ptr<uchar>(i);
for (int j = ; j < cols; j++){
p[j] = origal[cols - - j];
}
}
break;
case :
const Vec3b *origal3;
Vec3b *p3;
for (int i = ; i < rows; i++) {
origal3 = src.ptr<Vec3b>(i);
p3 = dst.ptr<Vec3b>(i);
for (int j = ; j < cols; j++){
p3[j] = origal3[cols - - j];
}
}
break;
default:
break;
} } int main(void)
{
Mat src = imread("Rise&Shine.jpg");
Mat dst;
dst = Mat::zeros(src.size(), src.type());
hMirrorTrans(src, dst);
imshow("原图像", src);
imshow("镜像对称图像", dst);
waitKey();
return ;
}

  运行结果:

  原图像:

  

  镜像对称图像:

  

 

最新文章

  1. LINQ to SQL语句(8)之Concat/Union/Intersect/Except
  2. python爬虫学习(4) —— 手刃「URP教务系统」
  3. [转]JUnit-4.11使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误
  4. Java从网络读取图片并保存至本地
  5. 重命名PDF打印文件名
  6. Number plate recognition with Tensorflow
  7. mahout协同过滤算法
  8. mssql 获取表结构信息
  9. ubuntu 下 github 使用方法 以及异常修改
  10. 浅谈 js 正则字面量 与 new RegExp 执行效率
  11. 2015 Multi-University Training Contest 9
  12. 【转】Linux强大命令 Awk 20分钟入门介绍
  13. CTR预估中的贝叶斯平滑方法及其代码实现
  14. Flink从入门到放弃(入门篇1)-Flink是什么
  15. Python链表的实现与使用(单向链表与双向链表)
  16. 牛客小白月赛13 小A的回文串(Manacher)
  17. 牛客练习赛26—D xor序列 —线性基
  18. JVM GC-----2、垃圾标记算法(一)
  19. hdu 5055
  20. wai

热门文章

  1. Beta版本——冲刺计划及安排
  2. 清除TFS版本控制信息
  3. API与软件架构
  4. tomcat7禁用catalina.out输出
  5. yield return 和 yield break
  6. tp三大自动
  7. 织梦DedeCms用SQL语句调用数据库任意内容方法
  8. iOS欢迎界面Launch Screen动态加载广告
  9. JAVA Socket 实现HTTP与HTTPS客户端发送POST与GET方式请求
  10. explicit构造函数