Hello guys,
I am trying to write a simple code which can iterate trough the frames on the host.
I am getting this error:
“RuntimeError: Communication exception - possible device error/misconfiguration. Original message 'Couldn't read data from stream: 'input' (X_LINK_ERROR)’”
I have simplified the class that I wrote. Here is the code:
class OakReader:
def __init__(self,
source,
fps=40):
self.source = str(source)
self.fps = fps
print('start pipeline')
pipeline = dai.Pipeline()
if source == 'left':
cam = pipeline.create(dai.node.MonoCamera)
cam.setBoardSocket(dai.CameraBoardSocket.LEFT)
# reslution
cam.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
elif source == 'right':
cam = pipeline.create(dai.node.MonoCamera)
cam.setBoardSocket(dai.CameraBoardSocket.RIGHT)
cam.setResolution(dai.MonoCameraProperties.SensorResolution.THE_40_P)
# set camera fps
cam.setFps(self.fps)
print(cam.getFps())
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName('input')
# attach camera to output xlink
cam.out.link(xout.input)
device = dai.Device(pipeline,usb2Mode=True)
# get output queues
self.queue = device.getOutputQueue(name='input',maxSize=1)
self.read_frame = self._read_frame
def __iter__(self):
"""Iterator for reading frames
Returns:
OakReader: can be used in next function or loops directly
"""
return self
def __next__(self):
"""Returns next frame read from stream
Returns:
the latest frame read from the stream
"""
frame = self.read_frame()
self._count += 1
return frame
def _read_frame(self):
"""Read frame from stream and return frame
Returns:
the latest frame read from the stream if flag is True else None.
"""
frame = self.queue.get()
return frame.getCvFrame()
if name == "main":
source = "left"
fps = 40
oak_reader = OakReader(source=source, fps=fps)
for frame in oak_reader:
height, width = frame.shape
print(height)
print(width)
I have been struggling with this for a day now.
I cannot iterate through the frames. I get the error when I execute the for loop.
I really appreciate if anyone can help me...
Thank you very much.