質問編集履歴
1
質問の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,81 +2,13 @@
|
|
2
2
|
手の画像の指先のみを処理(色を変えたり、ぼかしたり)できるプログラムを作成中です。その過程で編集したい範囲を決めるために指先のみが描画されている画像を作ろうとしています。
|
3
3
|
|
4
4
|
###質問したいこと
|
5
|
-
1.指先のみを抽出するためのプログラムをどのように作れば良いかわかりません。
|
5
|
+
1.指先のみを抽出するためのプログラムをどのように作れば良いかわかりません。
|
6
|
-
|
7
6
|
2.現在私が考えている方法より簡単に指先のみを処理可能な方法があれば教えて頂きたいです。
|
8
7
|
よろしくお願いします。
|
9
|
-

|
10
|
-

|
11
|
-

|
12
8
|
|
13
|
-
###該当のソースコード
|
14
|
-
```python
|
15
|
-
#1枚目の画像を作るプログラム
|
16
|
-
import cv2
|
17
|
-
import numpy as np
|
18
|
-
import sys
|
19
9
|
|
20
|
-
#肌色領域のみを抽出
|
21
|
-
def mask(param):
|
22
|
-
img = cv2.imread("%s"%param[1])
|
23
|
-
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
24
|
-
lower = np.array([0, 30, 160])
|
25
|
-
upper = np.array([30, 150, 255])
|
26
|
-
img_mask = cv2.inRange(hsv, lower, upper)
|
27
10
|
|
28
|
-
img_color = cv2.bitwise_and(img, img, mask=img_mask)
|
29
|
-
cv2.imwrite("color.jpg", img_color)
|
30
|
-
return img_color
|
31
11
|
|
32
|
-
#最大面積を抽出することでノイズを除去
|
33
|
-
def labelling(im):
|
34
|
-
height, width = im.shape[:2]
|
35
|
-
kernel = np.ones((10,10),np.uint8)
|
36
|
-
|
37
|
-
#最大面積のみを白にする
|
38
|
-
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
|
39
|
-
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
|
40
|
-
label = cv2.connectedComponentsWithStats(gray)
|
41
|
-
|
42
|
-
data = np.delete(label[2], 0, 0)
|
43
|
-
max_index = np.argsort(data[:,4])[::-1][0] + 1
|
44
|
-
dst = label[1].reshape((-1))
|
45
|
-
|
46
|
-
for index in range(len(dst)):
|
47
|
-
if dst[index] == max_index:
|
48
|
-
dst[index] = 255;
|
49
|
-
else:
|
50
|
-
dst[index] = 0;
|
51
|
-
|
52
|
-
dst = dst.reshape((height, width))
|
53
|
-
#エラーが出たので一度保存してから処理を行う
|
54
|
-
cv2.imwrite("kekka_totyu.jpg",dst)
|
55
|
-
im_re = cv2.imread("kekka_totyu.jpg")
|
56
|
-
|
57
|
-
#画像からノイズを減らすために輪郭の中を白に染める
|
58
|
-
gray2 = cv2.cvtColor(im_re, cv2.COLOR_BGR2GRAY)
|
59
|
-
gray2 = cv2.threshold(gray2, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
|
60
|
-
image, contours, hierarchy = cv2.findContours(gray2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
|
61
|
-
im_con = cv2.drawContours(im_re, contours, 0, (255,255,255), -1,)
|
62
|
-
|
63
|
-
#クロージング処理
|
64
|
-
cv2.imwrite("kekka.jpg",im_con)
|
65
|
-
closing = cv2.morphologyEx(im_con, cv2.MORPH_CLOSE, kernel)
|
66
|
-
cv2.imwrite("closing10.jpg", closing)
|
67
|
-
|
68
|
-
return closing
|
69
|
-
|
70
|
-
if __name__ == '__main__':
|
71
|
-
param = sys.argv
|
72
|
-
gazou = labelling(mask(param))
|
73
|
-
```
|
74
|
-
|
75
12
|
###試したこと
|
76
13
|
現在は下記のリンクを参考にして、手の輪郭からカーブの度合いを調べた後、傾きによって指かどうかを判定して指先を検出しようかと考えています。
|
77
|
-
[ARToolKitの物体認識 その② 指認識](http://render.s73.xrea.com/pipe_render/2008/07/artoolkit-15.html)
|
14
|
+
[ARToolKitの物体認識 その② 指認識](http://render.s73.xrea.com/pipe_render/2008/07/artoolkit-15.html)
|
78
|
-
|
79
|
-
###補足情報(言語/FW/ツール等のバージョンなど)
|
80
|
-
Python 3.6.3
|
81
|
-
OpenCV 3.3.1
|
82
|
-
mac OS Sierra 10.12.5
|