fix: bad pipeline configuration
This commit is contained in:
parent
1715c122e2
commit
3d5ac90a57
@ -5,6 +5,7 @@ import events.events_pb2
|
|||||||
from google.protobuf.timestamp_pb2 import Timestamp
|
from google.protobuf.timestamp_pb2 import Timestamp
|
||||||
|
|
||||||
import depthai as dai
|
import depthai as dai
|
||||||
|
from depthai_sdk import getDeviceInfo
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
@ -20,61 +21,64 @@ class FramePublisher(Thread):
|
|||||||
self._img_width = img_width
|
self._img_width = img_width
|
||||||
self._img_height = img_height
|
self._img_height = img_height
|
||||||
self._pipeline = self._configure_pipeline()
|
self._pipeline = self._configure_pipeline()
|
||||||
|
self._device_info = getDeviceInfo("18443010012F6C1200")
|
||||||
|
|
||||||
def _configure_pipeline(self) -> dai.Pipeline:
|
def _configure_pipeline(self) -> dai.Pipeline:
|
||||||
logger.info("configure pipeline")
|
logger.info("configure pipeline")
|
||||||
pipeline = dai.Pipeline()
|
pipeline = dai.Pipeline()
|
||||||
|
|
||||||
cam_rgb = pipeline.create(dai.node.ColorCamera)
|
cam_rgb = pipeline.create(dai.node.ColorCamera)
|
||||||
cam_rgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
|
xout_rgb = pipeline.create(dai.node.XLinkOut)
|
||||||
cam_rgb.setInterleaved(False)
|
|
||||||
cam_rgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
|
|
||||||
|
|
||||||
# Define sources and outputs
|
xout_rgb.setStreamName("rgb")
|
||||||
manip = pipeline.create(dai.node.ImageManip)
|
|
||||||
|
|
||||||
manip_out = pipeline.create(dai.node.XLinkOut)
|
|
||||||
|
|
||||||
manip_out.setStreamName("manip")
|
|
||||||
|
|
||||||
# Properties
|
# Properties
|
||||||
cam_rgb.setBoardSocket(dai.CameraBoardSocket.RGB)
|
cam_rgb.setBoardSocket(dai.CameraBoardSocket.RGB)
|
||||||
cam_rgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
|
cam_rgb.setPreviewSize(width=self._img_width, height=self._img_height)
|
||||||
|
cam_rgb.setInterleaved(False)
|
||||||
manip.initialConfig.setResize(self._img_width, self._img_height)
|
cam_rgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.RGB)
|
||||||
|
cam_rgb.setFps(30)
|
||||||
|
|
||||||
# Linking
|
# Linking
|
||||||
cam_rgb.video.link(manip.inputImage)
|
cam_rgb.video.link(xout_rgb.input)
|
||||||
manip.out.link(manip_out.input)
|
|
||||||
logger.info("pipeline configured")
|
logger.info("pipeline configured")
|
||||||
return pipeline
|
return pipeline
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
logger.info("device %s", self._device_info)
|
||||||
# Connect to device and start pipeline
|
# Connect to device and start pipeline
|
||||||
with dai.Device(self._pipeline) as device:
|
with dai.Device(self._pipeline) as device:
|
||||||
|
logger.info('MxId: %s', device.getDeviceInfo().getMxId())
|
||||||
|
logger.info('USB speed: %s', device.getUsbSpeed())
|
||||||
|
logger.info('Connected cameras: %s', device.getConnectedCameras())
|
||||||
|
|
||||||
|
logger.info("output queues found: %s",device.getOutputQueueNames())
|
||||||
|
|
||||||
|
device.startPipeline()
|
||||||
# Queues
|
# Queues
|
||||||
queue_size = 8
|
queue_size = 4
|
||||||
queue_manip = device.getOutputQueue("manip", queue_size)
|
q_rgb = device.getOutputQueue("rgb", maxSize=queue_size, blocking=False)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
while queue_manip.has():
|
inRgb = q_rgb.get() # blocking call, will wait until a new data has arrived
|
||||||
im_resize = queue_manip.get().getData().getCvFrame()
|
|
||||||
|
|
||||||
is_success, im_buf_arr = cv2.imencode(".jpg", im_resize)
|
im_resize = inRgb.getCvFrame()
|
||||||
byte_im = im_buf_arr.tobytes()
|
|
||||||
|
|
||||||
timestamp = Timestamp()
|
is_success, im_buf_arr = cv2.imencode(".jpg", im_resize)
|
||||||
frame_msg = events.events_pb2.FrameMessage()
|
byte_im = im_buf_arr.tobytes()
|
||||||
frame_msg.id = events.events_pb2.FrameRef()
|
|
||||||
frame_msg.id.name = "robocar-oak-camera-oak"
|
|
||||||
frame_msg.id.id = timestamp.ToMilliseconds()
|
|
||||||
frame_msg.id.created_at = timestamp.GetCurrentTime()
|
|
||||||
frame_msg.frame = byte_im
|
|
||||||
|
|
||||||
self._mqtt_client.publish(topic=self._frame_topic,
|
timestamp = Timestamp()
|
||||||
payload=frame_msg.SerializeToString(),
|
frame_msg = events.events_pb2.FrameMessage()
|
||||||
qos=0,
|
frame_msg.id.name = "robocar-oak-camera-oak"
|
||||||
retain=False)
|
frame_msg.id.id = str(timestamp.ToMilliseconds())
|
||||||
|
frame_msg.id.created_at.FromMilliseconds(timestamp.ToMilliseconds())
|
||||||
|
frame_msg.frame = byte_im
|
||||||
|
|
||||||
|
self._mqtt_client.publish(topic=self._frame_topic,
|
||||||
|
payload=frame_msg.SerializeToString(),
|
||||||
|
qos=0,
|
||||||
|
retain=False)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("unexpected error")
|
logger.exception("unexpected error")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
paho-mqtt~=1.6.1
|
paho-mqtt~=1.6.1
|
||||||
docopt~=0.6.2
|
docopt~=0.6.2
|
||||||
depthai==2.14.1.0
|
depthai==2.14.1.0
|
||||||
|
depthai-sdk
|
||||||
opencv-python~=4.5.5.62
|
opencv-python~=4.5.5.62
|
||||||
google~=3.0.0
|
google~=3.0.0
|
||||||
google-api-core~=2.4.0
|
google-api-core~=2.4.0
|
||||||
|
Loading…
Reference in New Issue
Block a user