質問編集履歴
2
タイトル変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
OpenCVを用いたGPU処理
|
1
|
+
OpenCVを用いたGPU処理の際のプログラムエラー(Expected Ptr<cv::UMat> for argument)
|
body
CHANGED
File without changes
|
1
コードの修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -32,10 +32,31 @@
|
|
32
32
|
face = cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=3, minSize=(30, 30))
|
33
33
|
|
34
34
|
for (x, y, w, h) in face:
|
35
|
-
###モザイク処理
|
35
|
+
###モザイク処理
|
36
36
|
frame[y:y+h, x:x+w] = mosaic(frame[y:y+h, x:x+w], 0.01)
|
37
37
|
img_gpu_dst2 = frame
|
38
38
|
frame = img_gpu_dst2.download()
|
39
39
|
|
40
40
|
writer.write(frame)
|
41
|
+
|
42
|
+
|
43
|
+
# モザイク処理
|
44
|
+
def mosaic(img, alpha):
|
45
|
+
|
46
|
+
w = img.shape[1]
|
47
|
+
h = img.shape[0]
|
48
|
+
|
49
|
+
### Run with GPU
|
50
|
+
img_gpu_src = cv2.cuda_GpuMat()
|
51
|
+
img_gpu_dst = cv2.cuda_GpuMat()
|
52
|
+
|
53
|
+
# 最近傍法で縮小→拡大することでモザイク加工、GPU処理
|
54
|
+
img_gpu_src.upload(img)
|
55
|
+
img_gpu_dst = cv2.cuda.resize(img_gpu_src, (int(w*alpha), int(h*alpha)))
|
56
|
+
img_gpu_dst = cv2.cuda.resize(img_gpu_dst, (w, h), interpolation=cv2.INTER_NEAREST)
|
57
|
+
img = img_gpu_dst.download()
|
58
|
+
|
59
|
+
return img
|
60
|
+
|
61
|
+
|
41
62
|
```
|