Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Saves grabbed image or impro function return value, if specified
Parameters
----------
filename : str
Filename of grabbed image
Returns
-------
None
"""
if self._camera is None or not self._camera.IsOpen():
raise ValueError("Camera object {} is closed.".format(self._camera))
converter = pylon.ImageFormatConverter()
converter.OutputPixelFormat = pylon.PixelType_BGR8packed
converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
grab_result = self._camera.GrabOne(5000)
image = converter.Convert(grab_result)
img = image.GetArray()
if self._impro_function:
img = self._impro_function(img)
cv2.imwrite(filename, img)
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
return np.asarray(x)
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)]
def _run_continuous_shot(self, grab_strategy=pylon.GrabStrategy_LatestImageOnly,
window_size=None, image_folder='.'):
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()