Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
camera.Width.SetValue(new_width)
# The parameter MaxNumBuffer can be used to control the count of buffers
# allocated for grabbing. The default value of this parameter is 10.
camera.MaxNumBuffer = 5
# Start the grabbing of c_countOfImagesToGrab images.
# The camera device is parameterized with a default configuration which
# sets up free-running continuous acquisition.
camera.StartGrabbingMax(countOfImagesToGrab)
# Camera.StopGrabbing() is called automatically by the RetrieveResult() method
# when c_countOfImagesToGrab images have been retrieved.
while camera.IsGrabbing():
# 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.")
prediction_list=['cardboard', 'glass', 'metal', 'paper', 'plastic', 'trash']
model=load_model('models/model1.h5', custom_objects={'relu6': mobilenet.relu6})
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
numberOfImagesToGrab = 100
camera.StartGrabbingMax(numberOfImagesToGrab)
converter = pylon.ImageFormatConverter()
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
i=0
while camera.IsGrabbing():
time.sleep(0.005)
grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
if grabResult.GrabSucceeded():
# Access the image data.
print("SizeX: ", grabResult.Width)
print("SizeY: ", grabResult.Height)
#import ipdb; ipdb.set_trace()
img = converter.Convert(grabResult).GetArray()
cv2.imwrite('pic.png', img)
pred_img=pp_image(img)
yo=model.predict(pred_img)
pred=prediction_list[np.argmax(yo)]
cv2.putText(img, pred, (10,1000), cv2.FONT_HERSHEY_SIMPLEX, 5, (0,0,0), 5, False)
name='img'+str(i)+'.png'
cv2.imwrite(os.path.join('prediction_images', name), img)
i=i+1
#print("Gray value of first pixel: ", img[0, 0])
def read(self):
""" """
grabResult = self.camera.RetrieveResult(
5000, pylon.TimeoutHandling_ThrowException
)
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])
grabResult.Release()
return img
else:
return None
self._camera.StopGrabbing()
# converting to opencv bgr format
converter = pylon.ImageFormatConverter()
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
if(not self._impro_own_window):
cv2.namedWindow('camera_image', cv2.WINDOW_NORMAL | cv2.WINDOW_GUI_NORMAL)
if(window_size is not None):
cv2.resizeWindow('camera_image', window_size[0], window_size[1])
self._camera.StartGrabbing(grab_strategy)
try:
while(self._camera.IsGrabbing()):
grab_result = self._camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
if grab_result.GrabSucceeded():
# Access the image data
image = converter.Convert(grab_result)
img = image.GetArray()
if(self._impro_own_window):
self._impro_function(img)
elif(self._impro_function is not None):
img = self._impro_function(img)
if(not isinstance(img, np.ndarray)):
cv2.destroyAllWindows()
raise ValueError("The given impro_function must return a numpy array when own_window=False")
cv2.imshow('camera_image', img)
else:
cv2.imshow('camera_image', img)