Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Wait for an image and then retrieve it. A timeout of 5000 ms is used.
grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
# Image grabbed successfully?
if grabResult.GrabSucceeded():
# Access the image data.
print("SizeX: ", grabResult.Width)
print("SizeY: ", grabResult.Height)
img = grabResult.Array
print("Gray value of first pixel: ", img[0, 0])
else:
print("Error: ", grabResult.ErrorCode, grabResult.ErrorDescription)
grabResult.Release()
camera.Close()
except genicam.GenericException as e:
# Error handling.
print("An exception occurred.")
print(e.GetDescription())
exitCode = 1
sys.exit(exitCode)
print(converter.IsSupportedOutputFormat(pylon.PixelType_Mono8))
# Now we can check if conversion is required.
if converter.ImageHasDestinationFormat(grabResult):
# No conversion is needed. It can be skipped for saving processing
# time.
show_image(grabResult, "Grabbed image.")
else:
# Conversion is needed.
show_image(grabResult, "Grabbed image.")
show_image(targetImage, "Converted image.")
except genicam.GenericException as e:
print("Could not grab an image: ", e.GetDescription())
except genicam.GenericException as e:
print("An exception occurred. ", e.GetDescription())
def grab_image():
try:
camera = pylon.InstantCamera(
pylon.TlFactory.GetInstance().CreateFirstDevice())
camera.Open()
result = camera.GrabOne(100)
camera.Close()
return result
except genicam.GenericException as e:
print("Could not grab an image: ", e.GetDescription())