Skip to content

Commit

Permalink
opencv: fix frame import from buffer in new pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 19, 2023
1 parent 965d5af commit 1006712
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions plugins/opencv/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/opencv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@
"devDependencies": {
"@scrypted/sdk": "file:../../sdk"
},
"version": "0.0.67"
"version": "0.0.68"
}
21 changes: 11 additions & 10 deletions plugins/opencv/src/opencv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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
Expand Down

0 comments on commit 1006712

Please sign in to comment.