_genicam.InvalidArgumentException: Cannot convert image.
Hello,
I am facing a weird problem where an error mentioning the following, is occurring occasionally: buff = converter.Convert(res) File "/usr/local/lib/python3.10/site-packages/pypylon/pylon.py", line 6866, in Convert return _pylon.ImageFormatConverter_Convert(self, *args) _genicam.InvalidArgumentException: Cannot convert image. The passed source image is invalid. : InvalidArgumentException thrown
I am trying to convert my cameras output (Mono) into BGR format using the following code:
def capture():
tlf = py.TlFactory.GetInstance()
camera = py.InstantCamera(tlf.CreateFirstDevice())
camera.Open()
res = camera.GrabOne(1000)
converter = py.ImageFormatConverter()
converter.OutputPixelFormat = py.PixelType_BGR8packed
converter.OutputBitAlignment = py.OutputBitAlignment_MsbAligned
buff = converter.Convert(res)
image = buff.GetArray()
camera.Close()
return image
The error mentioned above is not popping up every time I run my program, rather its occurring occasionally for which I am not able to ascertain the reason. Does anyone have any suggestions or know how can I rectify this error.
Thanks in Advance, Srikar
may be the image buffer is not valid for some reason. Check if the grab result is valid before pass it to image converter
if result.GrabSucceeded():
buff = converter.Convert(res)