質問編集履歴

1

質問の修正

2018/02/11 11:32

投稿

uni_tt
uni_tt

スコア15

test CHANGED
File without changes
test CHANGED
@@ -6,143 +6,17 @@
6
6
 
7
7
  ###質問したいこと
8
8
 
9
- 1.指先のみを抽出するためのプログラムをどのように作れば良いかわかりません。1枚目の画像から2枚目のような指先のみが描画されている画像を作りたいです。現在は3枚目のような画像まで作れています。
9
+ 1.指先のみを抽出するためのプログラムをどのように作れば良いかわかりません。
10
-
11
-
12
10
 
13
11
  2.現在私が考えている方法より簡単に指先のみを処理可能な方法があれば教えて頂きたいです。
14
12
 
15
13
  よろしくお願いします。
16
14
 
17
- ![イメージ説明](23f6edd9dbaa53a596a03f83f4e6f56a.png)
18
-
19
- ![イメージ説明](71605180dade561c95b0ceba714a91b7.jpeg)
20
-
21
- ![イメージ説明](8b3ae69bbd19a762b9d54d1818d5a896.jpeg)
22
15
 
23
16
 
24
17
 
25
- ###該当のソースコード
26
-
27
- ```python
28
-
29
- #1枚目の画像を作るプログラム
30
-
31
- import cv2
32
-
33
- import numpy as np
34
-
35
- import sys
36
18
 
37
19
 
38
-
39
- #肌色領域のみを抽出
40
-
41
- def mask(param):
42
-
43
- img = cv2.imread("%s"%param[1])
44
-
45
- hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
46
-
47
- lower = np.array([0, 30, 160])
48
-
49
- upper = np.array([30, 150, 255])
50
-
51
- img_mask = cv2.inRange(hsv, lower, upper)
52
-
53
-
54
-
55
- img_color = cv2.bitwise_and(img, img, mask=img_mask)
56
-
57
- cv2.imwrite("color.jpg", img_color)
58
-
59
- return img_color
60
-
61
-
62
-
63
- #最大面積を抽出することでノイズを除去
64
-
65
- def labelling(im):
66
-
67
- height, width = im.shape[:2]
68
-
69
- kernel = np.ones((10,10),np.uint8)
70
-
71
-
72
-
73
- #最大面積のみを白にする
74
-
75
- gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
76
-
77
- gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
78
-
79
- label = cv2.connectedComponentsWithStats(gray)
80
-
81
-
82
-
83
- data = np.delete(label[2], 0, 0)
84
-
85
- max_index = np.argsort(data[:,4])[::-1][0] + 1
86
-
87
- dst = label[1].reshape((-1))
88
-
89
-
90
-
91
- for index in range(len(dst)):
92
-
93
- if dst[index] == max_index:
94
-
95
- dst[index] = 255;
96
-
97
- else:
98
-
99
- dst[index] = 0;
100
-
101
-
102
-
103
- dst = dst.reshape((height, width))
104
-
105
- #エラーが出たので一度保存してから処理を行う
106
-
107
- cv2.imwrite("kekka_totyu.jpg",dst)
108
-
109
- im_re = cv2.imread("kekka_totyu.jpg")
110
-
111
-
112
-
113
- #画像からノイズを減らすために輪郭の中を白に染める
114
-
115
- gray2 = cv2.cvtColor(im_re, cv2.COLOR_BGR2GRAY)
116
-
117
- gray2 = cv2.threshold(gray2, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
118
-
119
- image, contours, hierarchy = cv2.findContours(gray2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
120
-
121
- im_con = cv2.drawContours(im_re, contours, 0, (255,255,255), -1,)
122
-
123
-
124
-
125
- #クロージング処理
126
-
127
- cv2.imwrite("kekka.jpg",im_con)
128
-
129
- closing = cv2.morphologyEx(im_con, cv2.MORPH_CLOSE, kernel)
130
-
131
- cv2.imwrite("closing10.jpg", closing)
132
-
133
-
134
-
135
- return closing
136
-
137
-
138
-
139
- if __name__ == '__main__':
140
-
141
- param = sys.argv
142
-
143
- gazou = labelling(mask(param))
144
-
145
- ```
146
20
 
147
21
 
148
22
 
@@ -151,13 +25,3 @@
151
25
  現在は下記のリンクを参考にして、手の輪郭からカーブの度合いを調べた後、傾きによって指かどうかを判定して指先を検出しようかと考えています。
152
26
 
153
27
  [ARToolKitの物体認識 その② 指認識](http://render.s73.xrea.com/pipe_render/2008/07/artoolkit-15.html)
154
-
155
-
156
-
157
- ###補足情報(言語/FW/ツール等のバージョンなど)
158
-
159
- Python 3.6.3
160
-
161
- OpenCV 3.3.1
162
-
163
- mac OS Sierra 10.12.5