dora-robomaster / operators /cv2_encoder_op.py
haixuantao's picture
Encode image as png
f4392e4
raw
history blame
689 Bytes
import pyarrow as pa
from dora import DoraStatus
import cv2
import os
CAMERA_WIDTH = 960
CAMERA_HEIGHT = 540
ENCODING = os.getenv("ENCODING", ".jpg")
class Operator:
"""
Infering object from images
"""
def on_event(
self,
dora_event,
send_output,
) -> DoraStatus:
if dora_event["type"] == "INPUT":
frame = (
dora_event["value"].to_numpy().reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3))
)
retval, buffer = cv2.imencode(ENCODING, frame)
if retval:
send_output("encoded_image", pa.array([buffer]), dora_event["metadata"])
return DoraStatus.CONTINUE