from harvesters.core import Harvester from PIL import Image import numpy as np import os import sys h=Harvester() CTI_path=r'C:\Program Files\Matrox Imaging\Drivers\GenICam\GenTL\Producer\Win64\Matrox.CoaXPress.cti' if os.path.isfile(CTI_path): h.add_file(CTI_path) else: h.reset() with Exception as e: print(str(e)) sys.exit("could not find GenTL producer") # h.update_device_info_list() - is being made phased out h.update() print(str(h.device_info_list)) if (len(h.device_info_list) == 0): h.reset() sys.exit("No producer available in your system") ia=h.create_image_acquirer(0) ia.start_acquisition() for i in range(0,10): with ia.fetch_buffer() as buffer: component=buffer.payload.components[0] bpp=component.num_components_per_pixel if bpp>1: buf=component.data.reshape(component.height,component.width,int(component.ccleanum_components_per_pixel)) else: buf=component.data.reshape(component.height,component.width) if buf.dtype == 'uint8': pillow_image=Image.fromarray(buf).copy() pillow_image.save(r'C:\Users\Autologonuser\Desktop\try\tst'+f'\Image {i}'+'.png') elif bpp==1: pillow_image=Image.fromarray(buf).copy() pillow_image.save(r'C:\Users\Autologonuser\Desktop\try\tst'+f'\Image {i}'+'.png') else: sys.exit("color format not supported by PIL") print(f'saved image {i}') ia.stop_acquisition() ia.destroy() h.reset()