Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pypylon import pylon
- import cv2, numpy as np
- from concurrent.futures import ThreadPoolExecutor
- def save_image(self, img,name):
- np.save(name, img, allow_pickle=False)
- image_counter = 0
- serial_number = '23437639'
- info = None
- max_threads = 5
- pool = ThreadPoolExecutor(max_threads)
- for i in pylon.TlFactory.GetInstance().EnumerateDevices():
- if i.GetSerialNumber() == serial_number:
- info = i
- break
- else:
- print('Camera with {} serial number not found '.format(serial_number))
- if info is not None:
- camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateDevice(info))
- camera.Open()
- camera.ReverseY.SetValue(True)
- converter = pylon.ImageFormatConverter()
- converter.OutputPixelFormat = pylon.PixelType_BGR8packed
- converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
- camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly)
- print('starting to grab images')
- while camera.IsGrabbing():
- with ThreadPoolExecutor(max_workers=5) as executor:
- grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
- if grabResult.GrabSucceeded():
- img = converter.Convert(grabResult)
- img = img.GetArray()
- h, w, ch = img.shape
- image_counter += 1
- filename = f"./unprocessed_images/image-{image_counter}"
- print(f'\r save image = {image_counter}',end='',flush=True)
- executor.submit(save_image,filename,img,allow_picke=False)
- #np.save(filename,img, allow_pickle=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement