From 100671265e92e74fbdedb3663b5aacf7ffca382b Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Sat, 18 Mar 2023 17:00:14 -0700 Subject: [PATCH] opencv: fix frame import from buffer in new pipeline --- plugins/opencv/package-lock.json | 4 ++-- plugins/opencv/package.json | 2 +- plugins/opencv/src/opencv/__init__.py | 21 +++++++++++---------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/opencv/package-lock.json b/plugins/opencv/package-lock.json index 962695c552..467cedffe4 100644 --- a/plugins/opencv/package-lock.json +++ b/plugins/opencv/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/opencv", - "version": "0.0.67", + "version": "0.0.68", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@scrypted/opencv", - "version": "0.0.67", + "version": "0.0.68", "devDependencies": { "@scrypted/sdk": "file:../../sdk" } diff --git a/plugins/opencv/package.json b/plugins/opencv/package.json index e7e5e7c89e..979635de56 100644 --- a/plugins/opencv/package.json +++ b/plugins/opencv/package.json @@ -36,5 +36,5 @@ "devDependencies": { "@scrypted/sdk": "file:../../sdk" }, - "version": "0.0.67" + "version": "0.0.68" } diff --git a/plugins/opencv/src/opencv/__init__.py b/plugins/opencv/src/opencv/__init__.py index e920cf97a5..9798bdf949 100644 --- a/plugins/opencv/src/opencv/__init__.py +++ b/plugins/opencv/src/opencv/__init__.py @@ -220,17 +220,18 @@ async def run_detection_videoframe(self, videoFrame: VideoFrame, detection_sessi if width <= 640 and height < 640: scale = 1 resize = None - elif aspectRatio > 1: - scale = height / 300 - resize = { - 'height': 300, - 'width': int(300 * aspectRatio) - } else: - scale = width / 300 + if aspectRatio > 1: + scale = height / 300 + height = 300 + width = int(300 * aspectRatio) + else: + width = 300 + height = int(300 / aspectRatio) + scale = width / 300 resize = { - 'width': 300, - 'height': int(300 / aspectRatio) + 'width': width, + 'height': height, } buffer = await videoFrame.toBuffer({ @@ -239,7 +240,7 @@ async def run_detection_videoframe(self, videoFrame: VideoFrame, detection_sessi def convert_to_src_size(point, normalize = False): return point[0] * scale, point[1] * scale, True - mat = np.ndarray((videoFrame.height, videoFrame.width, self.pixelFormatChannelCount), buffer=buffer, dtype=np.uint8) + mat = np.ndarray((height, width, self.pixelFormatChannelCount), buffer=buffer, dtype=np.uint8) detections = self.detect( detection_session, mat, (width, height), convert_to_src_size) return detections