Skip to content

Commit

Permalink
#43 blur GpuMat with copying to CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
tomskikh committed Jan 26, 2023
1 parent 32fc3c6 commit 128760a
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions gpumat/dsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from typing import List

from savant.deepstream.opencv_utils import nvds_to_gpu_mat, apply_cuda_filter
from savant.deepstream.opencv_utils import nvds_to_gpu_mat
from savant.deepstream.utils import nvds_frame_meta_iterator, get_nvds_buf_surface

sys.path.append('../../')
Expand Down Expand Up @@ -46,7 +46,6 @@ def bus_call(bus, message, loop):
def pad_buffer_probe(
pad: Gst.Pad,
info: Gst.PadProbeInfo,
cuda_blur_filter: cv2.cuda.Filter,
cpu: bool,
measurements: List[float],
):
Expand All @@ -67,7 +66,15 @@ def pad_buffer_probe(
else:
with nvds_to_gpu_mat(gst_buffer, nvds_frame_meta) as frame_mat:
for x, y in rectangles:
apply_cuda_filter(cuda_blur_filter, frame_mat, (x, y, 30, 40))
roi = cv2.cuda.GpuMat(frame_mat, (x, y, 30, 40))
roi.upload(
cv2.GaussianBlur(
roi.download(),
(31, 31),
100,
100,
)
)
ts2 = time.time()
measurements.append((ts2 - ts1) * scale)

Expand Down Expand Up @@ -224,17 +231,9 @@ def main(args):
if not sink_pad:
sys.stderr.write("Unable to get sink pad")
else:
cuda_blur_filter: cv2.cuda.Filter = cv2.cuda.createGaussianFilter(
cv2.CV_8UC4,
cv2.CV_8UC4,
(31, 31),
100,
100,
)
sink_pad.add_probe(
Gst.PadProbeType.BUFFER,
pad_buffer_probe,
cuda_blur_filter,
is_cpu,
measurements,
)
Expand Down

0 comments on commit 128760a

Please sign in to comment.