OpenCVの基本的なしきい値処理

 

1つの#include " opencv2 / imgproc / imgproc.hpp " 
2の#include " opencv2 /のHighGUI / highgui.hpp " 
3の#include <STDLIB.H>
 4の#include <stdio.hの>
 5  
6  使用して 名前空間品種;
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  マットSRC、src_gray、DST。
17  のchar * window_nameが= " しきい値デモ" 18  
19  のchar * trackbar_type = " タイプ:\ nは0:バイナリ\ nは1:バイナリ逆\ N 2:切り捨て\ nは3:ゼロ\ nは4:ゼロ倒立" 20  のchar * trackbar_value = " " 21  
22  /// 自定义函数声明
23  のボイド Threshold_Demo(int型無効* );
 24  
25  / * *
 26  *主要機能@
 27   * / 
28  INTメイン(int型 ARGC、チャー ** 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である   (trackbar_value、createTrackbar
 45                    window_nameが、&、threshold_valueに
 46であり                   、MAX_VALUE、Threshold_Demo)
 47  
48    /// カスタマイズ初期化閾値関数
49    Threshold_Demo(00 );
 50  
51である   /// キー待ち。ESCの健康はプロセスを待って終了している場合。
52    一方、真の53   {
 54は、     INT C、
 55      C = waitKey(20である);
 56は、     IF((チャー)C == 27 57である        { BREAK ;}
 58     }
 59  
60  }
 61は、 
62である 
63である / * *
 64  * @カスタム閾値関数
 65   * / 
66  空隙 Threshold_Demo(INTボイド * 67  {
 68    / * 0:バイナリ閾値
 69       1:トランス2値化閾値
 70       2:カットオフ閾値
71       3:0阈值
 72       4:反0阈值
 73     * / 
74  
75    閾値(src_gray、DST、threshold_valueに、max_BINARY_value、threshold_type)。
76  
77    関数imshow(window_nameが、DST)。
78 }

おすすめ

転載: www.cnblogs.com/ybqjymy/p/12170906.html