一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
posts - 3121,comments - 209,views - 578万

 

复制代码
 1 #include "opencv2/imgproc/imgproc.hpp"
 2 #include "opencv2/highgui/highgui.hpp"
 3 #include <stdlib.h>
 4 #include <stdio.h>
 5 
 6 using namespace cv;
 7 
 8 /// 全局变量定义及赋值
 9 
10 int threshold_value = 0;
11 int threshold_type = 3;;
12 int const max_value = 255;
13 int const max_type = 4;
14 int const max_BINARY_value = 255;
15 
16 Mat src, src_gray, dst;
17 char* window_name = "Threshold Demo";
18 
19 char* trackbar_type = "Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted";
20 char* trackbar_value = "Value";
21 
22 /// 自定义函数声明
23 void Threshold_Demo( int, void* );
24 
25 /**
26  * @主函数
27  */
28 int main( int argc, char** argv )
29 {
30   /// 读取一副图片,不改变图片本身的颜色类型(该读取方式为DOS运行模式)
31   src = imread( argv[1], 1 );
32 
33   /// 将图片转换成灰度图片
34   cvtColor( src, src_gray, CV_RGB2GRAY );
35 
36   /// 创建一个窗口显示图片
37   namedWindow( window_name, CV_WINDOW_AUTOSIZE );
38 
39   /// 创建滑动条来控制阈值
40   createTrackbar( trackbar_type,
41                   window_name, &threshold_type,
42                   max_type, Threshold_Demo );
43 
44   createTrackbar( trackbar_value,
45                   window_name, &threshold_value,
46                   max_value, Threshold_Demo );
47 
48   /// 初始化自定义的阈值函数
49   Threshold_Demo( 0, 0 );
50 
51   /// 等待用户按键。如果是ESC健则退出等待过程。
52   while(true)
53   {
54     int c;
55     c = waitKey( 20 );
56     if( (char)c == 27 )
57       { break; }
58    }
59 
60 }
61 
62 
63 /**
64  * @自定义的阈值函数
65  */
66 void Threshold_Demo( int, void* )
67 {
68   /* 0: 二进制阈值
69      1: 反二进制阈值
70      2: 截断阈值
71      3: 0阈值
72      4: 反0阈值
73    */
74 
75   threshold( src_gray, dst, threshold_value, max_BINARY_value,threshold_type );
76 
77   imshow( window_name, dst );
78 }
复制代码
posted on   一杯清酒邀明月  阅读(354)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示