回答編集履歴

1

変更の為

2016/11/14 13:50

投稿

MasahikoHirata
MasahikoHirata

スコア3747

test CHANGED
@@ -6,27 +6,27 @@
6
6
 
7
7
  {
8
8
 
9
- double discard_ratio = 0.05;
9
+ double discard_ratio = 0.05; // 棄却するもととなる比率
10
10
 
11
- int hists[3][256];
11
+ int hists[3][256]; // 3色(BGR)と各0-255までの値からヒストグラム(出現頻度)を格納する二次元配列
12
12
 
13
13
 
14
14
 
15
- memset(hists, 0, 3*256*sizeof(int));
15
+ memset(hists, 0, 3*256*sizeof(int)); // 二次元配列hist[][]を0で初期化
16
16
 
17
- for (int y = 0; y < mat.rows; ++y) {
17
+ for (int y = 0; y < mat.rows; ++y) { // 引数で渡された matの行数の間をyが示す。
18
18
 
19
- uchar* ptr = mat.ptr<uchar>(y);
19
+ uchar* ptr = mat.ptr<uchar>(y); // ポインタptrはその先頭のアドレスを示す。
20
20
 
21
- for (int x = 0; x < mat.cols; ++x)
21
+ for (int x = 0; x < mat.cols; ++x) // 引数で渡された matの列数の間をxが示す。
22
22
 
23
23
  {
24
24
 
25
- for (int j = 0; j < 3; ++j)
25
+ for (int j = 0; j < 3; ++j)   // jは0-2これはBGRの各色情報に基づいている。
26
26
 
27
27
  {
28
28
 
29
- hists[j][ptr[x * 3 + j]] += 1;
29
+ hists[j][ptr[x * 3 + j]] += 1; // histの示す内容に1を加えていく。(=1でよくねぇ?)
30
30
 
31
31
  }
32
32
 
@@ -36,13 +36,13 @@
36
36
 
37
37
  // cumulative hist
38
38
 
39
- int total = mat.cols*mat.rows;
39
+ int total = mat.cols*mat.rows; // 引数で渡されたmatの行×列がtotal
40
40
 
41
- int vmin[3], vmax[3];
41
+ int vmin[3], vmax[3]; // BGRの各色の最小値・最大数を入れる配列
42
42
 
43
43
 
44
44
 
45
- for (int i = 0; i < 3; ++i)
45
+ for (int i = 0; i < 3; ++i) // 色毎(0=B、1=G、2=R)でアクセス。
46
46
 
47
47
  {
48
48
 
@@ -50,13 +50,13 @@
50
50
 
51
51
  {
52
52
 
53
- hists[i][j + 1] += hists[i][j];
53
+ hists[i][j + 1] += hists[i][j]; // おそらく順番に 1,2,3,4,5という配列を作る。
54
54
 
55
55
  }
56
56
 
57
- vmin[i] = 0;
57
+ vmin[i] = 0; // 各色の最小値を初期化
58
58
 
59
- vmax[i] = 255;
59
+ vmax[i] = 255; // 各色の最大値を初期化
60
60
 
61
61
  while (hists[i][vmin[i]] < discard_ratio * total)
62
62