OpenCV学习:将图像转为二值图像(函数cvtColor和函数threshold)
来源:互联网 发布:网络舞曲最红 编辑:程序博客网 时间:2024/04/29 01:51
想换一下CSDN账户的头像,换成自己的真实的头像,但是又不想那么直接,干脆就把头像转换成二值图得了,因为从二值图像是推不出来原图的。这个过程需要OpenCV的两个函数,第一个函数是彩色图像转化为灰度图像:cvtColor函数;下一个函数是由灰度图转化为二值图像函数:threshold函数。用法很简单,代码如下:
[cpp] view plaincopyprint?
- cvtColor(img_origin,img_gray,CV_BGR2GRAY);
- threshold(img_gray,img_binary,145,255,THRESH_BINARY);
- imwrite("/home/hon/result.jpg",img_binary);
- imshow("binary
image" ,img_binary);
cvtColor函数:
原型:
[cpp] view plaincopyprint?
- void
cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0 )
code的模式包括:
CV_RGB2GRAY:<彩色图像---灰度图像>
CV_BGR2YCrCb, CV_RGB2YCrCb, CV_YCrCb2BGR, CV_YCrCb2RGB
CV_BGR2HSV, CV_RGB2HSV, CV_HSV2BGR, CV_HSV2RGB
更多的变换信息可以参考 OpenCV 2.4.5 documentation:http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#void cvtColor(InputArray src, OutputArray dst, int code, int dstCn)
threshold函数:
原型:
[cpp] view plaincopyprint?
- double
threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
code的模式包括:
参考相关文档:OpenCV 2.4.5 documentation:http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=threshold#cv.Threshold
注意:threshold函数针对的是单通道图像,这个一定要注意!
0 0
- OpenCV学习:将图像转为二值图像(函数cvtColor和函数threshold)
- OpenCV学习:将图像转为二值图像(函数cvtColor和函数threshold)
- 【图像处理】OpenCV函数threshold的使用
- opencv学习(一)实现将彩色图像转换成灰度图像和二值图像
- 图像的二值化函数 threshold
- opencv学习(二十八)之基本图像阈值操作threshold
- openCV二值函数threshold的使用
- 【OpenCV3图像处理】颜色空间转换(二)转换函数 cvtColor()
- 【OpenCV学习笔记】【函数学习】十一(读入图像﹑显示图像和保存图像)
- opencv2函数学习之threshold:实现图像阈值化
- opencv学习之threshold函数
- opencv学习篇(1) 图像处理和图像识别中常用的OpenCV函数
- 【拜小白opencv】2图像彩色空间转换,RGB转灰度图等。cvtColor()函数
- OpenCV系统学习:二、基本图像处理函数
- opencv学习(二十七)之图像缩放函数resize
- matlab 自定义算法将图像二分阈值 (binary threshold)化,im2bw or imbinarize函数用法
- opencv2函数学习之threshold:实现图像阈值化 在opencv2中,threshold函数可以进行阈值化操作。 double threshold( const Mat& src, M
- OpenCV学习笔记(十八)——图像的各种变换(cvtColor*+)imgproc
- frostwire项目源码分析
- 希尔排序(shellsort)
- Hibernate处理一个实体映射多张相同结构的数据表--动态映射
- Mybatis入门(自己入门)
- 多客户端上传服务器文档使用scp命令不需要输入密码
- OpenCV学习:将图像转为二值图像(函数cvtColor和函数threshold)
- 为eclipse离线安装hibernate tools插件
- Algorithms—150.Evaluate Reverse Polish Notation
- Github上README.md介绍 语法
- 简单计算器(递归写法)
- 字符串转换成数字以及注意事项
- 1+2+3+......+n
- ProtocolBuffer for Objective-C 运行环境配置(真正测试过的3.0版本编译)
- AndroidJNI.SetObjectField 设置对象域