| @@ -1,6 +1,6 @@ | |||
| import os | |||
| import argparse | |||
| from cv2 import cv2 # Importing cv2 this way remove error warnings`` | |||
| import cv2 | |||
| import numpy as np | |||
| import pyarrow as pa | |||
| @@ -129,25 +129,24 @@ def main(): | |||
| event_id = event["id"] | |||
| if event_id == "image": | |||
| arrow_image = event["value"][0] | |||
| storage = event["value"] | |||
| metadata = event["metadata"] | |||
| encoding = metadata["encoding"] | |||
| width = metadata["width"] | |||
| height = metadata["height"] | |||
| encoding = arrow_image["encoding"].as_py() | |||
| if encoding == "bgr8": | |||
| channels = 3 | |||
| storage_type = np.uint8 | |||
| else: | |||
| raise RuntimeError(f"Unsupported image encoding: {encoding}") | |||
| image = { | |||
| "width": np.uint32(arrow_image["width"].as_py()), | |||
| "height": np.uint32(arrow_image["height"].as_py()), | |||
| "encoding": encoding, | |||
| "channels": channels, | |||
| "data": arrow_image["data"].values.to_numpy().astype(storage_type), | |||
| } | |||
| plot.frame = np.reshape( | |||
| image["data"], (image["height"], image["width"], image["channels"]) | |||
| plot.frame = ( | |||
| storage.to_numpy() | |||
| .astype(storage_type) | |||
| .reshape((height, width, channels)) | |||
| .copy() # Copy So that we can add annotation on the image | |||
| ) | |||
| plot_frame(plot) | |||
| @@ -1,6 +1,6 @@ | |||
| import os | |||
| import argparse | |||
| from cv2 import cv2 # Importing cv2 this way remove error warnings`` | |||
| import cv2 | |||
| import numpy as np | |||
| import pyarrow as pa | |||
| @@ -105,14 +105,14 @@ def main(): | |||
| if image_width is not None and image_height is not None: | |||
| frame = cv2.resize(frame, (image_width, image_height)) | |||
| image = { | |||
| "width": np.uint32(frame.shape[1]), | |||
| "height": np.uint32(frame.shape[0]), | |||
| "encoding": "bgr8", | |||
| "data": frame.ravel(), | |||
| } | |||
| storage = pa.array(frame.ravel()) | |||
| node.send_output("image", pa.array([image]), event["metadata"]) | |||
| metadata = event["metadata"] | |||
| metadata["width"] = int(frame.shape[1]) | |||
| metadata["height"] = int(frame.shape[0]) | |||
| metadata["encoding"] = "bgr8" | |||
| node.send_output("image", storage, metadata) | |||
| elif event_type == "ERROR": | |||
| raise RuntimeError(event["error"]) | |||
| @@ -45,8 +45,11 @@ def main(): | |||
| event_id = event["id"] | |||
| if event_id == "image": | |||
| arrow_image = event["value"][0] | |||
| encoding = arrow_image["encoding"].as_py() | |||
| storage = event["value"] | |||
| metadata = event["metadata"] | |||
| encoding = metadata["encoding"] | |||
| width = metadata["width"] | |||
| height = metadata["height"] | |||
| if encoding == "bgr8": | |||
| channels = 3 | |||
| @@ -54,18 +57,11 @@ def main(): | |||
| else: | |||
| raise RuntimeError(f"Unsupported image encoding: {encoding}") | |||
| image = { | |||
| "width": np.uint32(arrow_image["width"].as_py()), | |||
| "height": np.uint32(arrow_image["height"].as_py()), | |||
| "encoding": encoding, | |||
| "channels": channels, | |||
| "data": arrow_image["data"].values.to_numpy().astype(storage_type), | |||
| } | |||
| frame = image["data"].reshape( | |||
| (image["height"], image["width"], image["channels"]) | |||
| frame = ( | |||
| storage.to_numpy() | |||
| .astype(storage_type) | |||
| .reshape((height, width, channels)) | |||
| ) | |||
| if encoding == "bgr8": | |||
| frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB) | |||
| else: | |||