質問編集履歴
2
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
OpenCVを用いたGPU処理
|
1
|
+
OpenCVを用いたGPU処理の際のプログラムエラー(Expected Ptr<cv::UMat> for argument)
|
test
CHANGED
File without changes
|
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
for (x, y, w, h) in face:
|
68
68
|
|
69
|
-
###モザイク処理
|
69
|
+
###モザイク処理
|
70
70
|
|
71
71
|
frame[y:y+h, x:x+w] = mosaic(frame[y:y+h, x:x+w], 0.01)
|
72
72
|
|
@@ -78,4 +78,46 @@
|
|
78
78
|
|
79
79
|
writer.write(frame)
|
80
80
|
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
# モザイク処理
|
86
|
+
|
87
|
+
def mosaic(img, alpha):
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
w = img.shape[1]
|
92
|
+
|
93
|
+
h = img.shape[0]
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
### Run with GPU
|
98
|
+
|
99
|
+
img_gpu_src = cv2.cuda_GpuMat()
|
100
|
+
|
101
|
+
img_gpu_dst = cv2.cuda_GpuMat()
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
# 最近傍法で縮小→拡大することでモザイク加工、GPU処理
|
106
|
+
|
107
|
+
img_gpu_src.upload(img)
|
108
|
+
|
109
|
+
img_gpu_dst = cv2.cuda.resize(img_gpu_src, (int(w*alpha), int(h*alpha)))
|
110
|
+
|
111
|
+
img_gpu_dst = cv2.cuda.resize(img_gpu_dst, (w, h), interpolation=cv2.INTER_NEAREST)
|
112
|
+
|
113
|
+
img = img_gpu_dst.download()
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
return img
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
81
123
|
```
|