【opencv练习18 - 基本阈值操作】
2016-09-04 12:47
260 查看
/***************************************************** 测试程序 【基本阈值操作】 时间:2016年8月26日 *****************************************************/ /// Global variables int threshold_value = 0; //阈值变量 int threshold_type = 3; //阈值类型 int const max_value = 255; //像素最大值 int const max_type = 4; //最大类型编号 int const max_BINARY_value = 255; //二值化最大值 Mat src, src_gray, dst; const char* window_name = "Threshold Demo"; const char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted"; const char* trackbar_value = "Value"; /// Function headers void Threshold_Demo( int, void* ); int main(void) { /// Load an image src = imread("YY01.jpg" , 1 ); /// Convert the image to Gray cvtColor( src, src_gray, COLOR_RGB2GRAY ); /// Create a window to display results namedWindow( window_name, WINDOW_AUTOSIZE ); /// Create Trackbar to choose type of Threshold createTrackbar( trackbar_type, window_name, &threshold_type, max_type, Threshold_Demo ); createTrackbar( trackbar_value, window_name, &threshold_value, max_value, Threshold_Demo ); /// Call the function to initialize Threshold_Demo( 0, 0 ); /// Wait until user finishes program for(;;) { int c; c = waitKey( 20 ); if( (char)c == 27 ){ break; } } } //【回调函数】 void Threshold_Demo( int, void* ) { // 0: Binary //二值化 // 1: Binary Inverted //反向二值化 // 2: Threshold Truncated //超阈值截断 // 3: Threshold to Zero //低于阈值,置0 // 4: Threshold to Zero Inverted //高于阈值,置0 //参数,sec,dst,阈值,最大阈值(二值常用),阈值类型 threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type ); imshow( window_name, dst ); }
二值化
反向二值化
超阈值截断
低于阈值,置0
高于阈值,置0
相关文章推荐
- opencv c++函数 imgproc模块 5 基本的阈值操作
- OpenCV基本的阈值操作
- (23)Air Band OpenCV2.4.13_基本阈值操作
- OpenCV学习13--基本阈值操作
- opencv学习笔记--基本阈值操作
- OpenCV学习第十五篇:基本阈值操作
- opencv学习(二十八)之基本图像阈值操作threshold
- OpenCV之imgproc 模块. 图像处理(1)图像平滑处理 腐蚀与膨胀(Eroding and Dilating) 更多形态学变换 图像金字塔 基本的阈值操作
- opencv-基础阈值操作
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- 我的OpenCV学习笔记(16):利用工具条调用基本的形态学操作
- opencv图像处理基本操作
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- oracle入门触发器,存储过程基本操作练习
- OPENCV基本操作
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- OpenCV 编程简介(矩阵/图像/视频的基本读写操作)
- 第2章_基本数据类型和基本操作_编程练习Exercise2.7通过创建窗口进行大小写的切换
- 【OpenCV学习】矩阵基本操作
- 学习opencv第三章 基本数据类型 ,矩阵创建,操作,访问