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

質問編集履歴

2

codeブロックしました

2018/08/06 11:20

投稿

empelt
empelt

スコア6

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,33 @@
1
+ ```ここに言語を入力
2
+ import cv2
3
+ import numpy as np
4
+
5
+ image_path = "pisu5.jpg"
6
+ src = cv2.imread(image_path)
7
+
8
+ def skin_detect(src):
9
+
10
+ hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)
11
+
12
+ hsv_min = np.aray([0, 30, 60])
13
+ hsv_max = np.array([20, 150, 255])
14
+ mask = cv2.inRange(hsv, hsv_min, hsv_max)
15
+ return mask
16
+
17
+ def mosaic(src, ratio=0.1):
18
+ small = cv2.resize(src, None, fx=ratio, fy=ratio, interpolation=cv2.INTER_NEAREST)
19
+ return cv2.resize(small, src.shape[:2][::-1], interpolation=cv2.INTER_NEAREST)
20
+
21
+ def mosaic_area(src, x, y, width, height, ratio=0.02):
22
+ dst = src.copy()
23
+ dst[y:y + height , x:x + width] = mosaic(dst[y:y + height, x:x + width], ratio)
24
+ return dst
25
+
26
+
27
+ for ??????
28
+ cv2.imwrite("pisu5_detect.jpg", ??????)
29
+
1
- ```
30
+ ``````
2
31
  コード
3
32
  ```### 前提・実現したいこと
4
33
  画像から肌色を検出して検出域にモザイクをかけるプログラムを作っています。

1

codeブロックいたしました

2018/08/06 11:20

投稿

empelt
empelt

スコア6

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,6 @@
1
+ ```
2
+ コード
1
- ### 前提・実現したいこと
3
+ ```### 前提・実現したいこと
2
4
  画像から肌色を検出して検出域にモザイクをかけるプログラムを作っています。
3
5
  しかし、モザイクをかけて画像を保存するところがいまいち分からないので教えていただきたいです。
4
6
  あと、もし不足している文があったらご指摘願いたいです。
@@ -8,13 +10,13 @@
8
10
 
9
11
 
10
12
  ### 該当のソースコード
11
- import cv2
13
+ import cv2
12
- import numpy as np
14
+ import numpy as np
13
15
 
14
- image_path = "pisu5.jpg"
16
+ image_path = "pisu5.jpg"
15
- src = cv2.imread(image_path)
17
+ src = cv2.imread(image_path)
16
18
 
17
- def skin_detect(src):
19
+ def skin_detect(src):
18
20
 
19
21
  hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV)
20
22
 
@@ -23,11 +25,11 @@
23
25
  mask = cv2.inRange(hsv, hsv_min, hsv_max)
24
26
  return mask
25
27
 
26
- def mosaic(src, ratio=0.1):
28
+ def mosaic(src, ratio=0.1):
27
29
  small = cv2.resize(src, None, fx=ratio, fy=ratio, interpolation=cv2.INTER_NEAREST)
28
30
  return cv2.resize(small, src.shape[:2][::-1], interpolation=cv2.INTER_NEAREST)
29
31
 
30
- def mosaic_area(src, x, y, width, height, ratio=0.02):
32
+ def mosaic_area(src, x, y, width, height, ratio=0.02):
31
33
  dst = src.copy()
32
34
  dst[y:y + height , x:x + width] = mosaic(dst[y:y + height, x:x + width], ratio)
33
35
  return dst