teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

移植版コードでR=G=Bの時の色相判定が狂っていたため修正

2018/05/01 20:32

投稿

Bongo
Bongo

スコア10816

answer CHANGED
@@ -94,22 +94,22 @@
94
94
  // Figure 11: The algorithm of the modified HSV technique for detecting skin color regions.
95
95
 
96
96
  float3 c = tex2D(_MainTex, i.uv).rgb * 255.0;
97
-
97
+
98
98
  float I = dot(float3(0.596, -0.274, -0.322), c);
99
99
  float V = max(c.r, max(c.g, c.b));
100
100
  float D = V - min(c.r, min(c.g, c.b));
101
101
  float S = D / V;
102
102
  float3 H3 = float3(c.g - c.b, 2.0 - c.r + c.b, 4.0 - c.g + c.r) / (6.0 * D);
103
- float H = dot(floor(c / V) * H3, 1.0);
103
+ float H = dot(floor(c / V) * H3, 1.0 - floor(saturate(dot(normalize(c), 1.0))));
104
104
 
105
105
  float result = step(0.20, S) * step(S, 0.75) * step(0.35, V) * step(0.0, H) * step(H, 25.0) * step(I, 90.0) * step(20.0, I);
106
-
106
+
107
107
  return fixed4(result, result, result, 1.0);
108
108
  }
109
109
  ```
110
110
 
111
111
  Figure 11のコードを使った場合
112
112
  ※ちゃんと移植できたか自信がないので、オリジナルの論文をご覧になった方がいいかと思います...
113
- ![例2](f011bc38fdb2260232734714076e9a38.png)
113
+ ![例2](6cc3056015e2c5126104da9a46a7237c.png)
114
114
 
115
115
  やはり撮影条件や背景によって抽出難易度はころころ変わってしまうようですね。うまくやるにはいろいろと試行錯誤が必要そうです。