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