Skip to content

Commit

Permalink
#43 measure rectangles blurring
Browse files Browse the repository at this point in the history
  • Loading branch information
tomskikh committed Jan 26, 2023
1 parent 062254d commit 32fc3c6
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions gpumat/dsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import time
from typing import List

import numpy as np

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

sys.path.append('../../')
Expand Down Expand Up @@ -48,6 +46,7 @@ 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 @@ -59,22 +58,16 @@ def pad_buffer_probe(
if cpu:
with get_nvds_buf_surface(gst_buffer, nvds_frame_meta) as np_frame:
for x, y in rectangles:
cv2.rectangle(
np_frame,
(x, y),
(x + 100, y + 200),
RECT_COLOR,
4,
np_frame[y : y + 40, x : x + 30] = cv2.GaussianBlur(
np_frame[y : y + 40, x : x + 30],
(31, 31),
100,
100,
)
else:
with nvds_to_gpu_mat(gst_buffer, nvds_frame_meta) as gpu_mat:
with nvds_to_gpu_mat(gst_buffer, nvds_frame_meta) as frame_mat:
for x, y in rectangles:
draw_rect(
gpu_mat,
(x, y, x + 100, y + 200),
RECT_COLOR,
4,
)
apply_cuda_filter(cuda_blur_filter, frame_mat, (x, y, 30, 40))
ts2 = time.time()
measurements.append((ts2 - ts1) * scale)

Expand Down Expand Up @@ -231,9 +224,17 @@ 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 32fc3c6

Please sign in to comment.