Esempio n. 1
0
	def __init__(self,maxCamerasToUse,secperframe):
		try:
			self.spf = secperframe
			# Get the transport layer factory.
			tlFactory = pylon.TlFactory.GetInstance()
		
			# Get all attached devices and exit application if no device is found.
			devices = tlFactory.EnumerateDevices()
			if len(devices) == 0:
				raise pylon.RUNTIME_EXCEPTION("No camera present.")
		
			# Create an array of instant cameras for the found devices and avoid exceeding a maximum number of devices.
			self.cameras = pylon.InstantCameraArray(min(len(devices), maxCamerasToUse))
		
			self.l = self.cameras.GetSize()
			
			self.dimarr=np.zeros((self.l,2),dtype='uint8')
			self.sernum=[None]*self.l
			# Create and attach all Pylon Devices.
			for i, cam in enumerate(self.cameras):
				#Some parameters I'm using now, may change in future.
				cam.Attach(tlFactory.CreateDevice(devices[i]))
				cam.Open()
				cam.AcquisitionFrameRateEnable.SetValue(True)
				cam.AcquisitionFrameRate.SetValue(1/secperframe)
				cam.OffsetX.SetValue(0)
				cam.OffsetY.SetValue(0)
				self.dimarr[i] = [cam.Height.GetMax(),cam.Width.GetMax()]
				self.sernum[i]=cam.GetDeviceInfo().GetSerialNumber()
				cam.ExposureAuto.SetValue('Off')
				cam.GainAuto.SetValue('Off')
				cam.Close()
		except genicam.GenericException as e:
			# Error handling
			print("An exception occurred.", e.GetDescription())		
Esempio n. 2
0
    def start(self):
        """Main loop. Setup camera, run, close and save."""
        self.print_info()

        self.camera.Open()
        self.set_parameters()
        self.set_output_file()
        self.set_counter()
        self.set_exp_output()
        self.set_user_output()
        self.enable_chunks()

        self.imageWindow.Show()
        self.camera.StartGrabbing(pylon.GrabStrategy_OneByOne)

        while self.camera.IsGrabbing():
            self.counter += 1
            self.grabResult = self.camera.RetrieveResult(
                5000, pylon.TimeoutHandling_ThrowException)
            # Check to see if a buffer containing chunk data has been received.
            if pylon.PayloadType_ChunkData != self.grabResult.PayloadType:
                raise pylon.RUNTIME_EXCEPTION(
                    "Unexpected payload type received.")
            # Since we have activated the CRC Checksum feature, we can check
            # the integrity of the buffer first.
            # Note: Enabling the CRC Checksum feature is not a prerequisite for using
            # chunks. Chunks can also be handled when the CRC Checksum feature is deactivated.
            if self.grabResult.HasCRC() and self.grabResult.CheckCRC(
            ) == False:
                raise pylon.RUNTIME_EXCEPTION("Image was damaged!")
            self.grab_image()

        self.camera.Close()
        with open(self.parameters['output_csv'], 'w', newline='') as f:
            writer = csv.writer(f)
            writer.writerows(self.data_out)
        # self.disable_chunks()
        # Release OpenCV output file
        # self.output.release()
        # Close skvideo file
        self.output.close()
Esempio n. 3
0
    def __init__(self, camsToUse):

        self.tlFactory = pylon.TlFactory.GetInstance()
        maxCamerasToUse = camsToUse

        # Get all attached devices and exit application if no device is found.
        self.devices = self.tlFactory.EnumerateDevices()
        if len(self.devices) == 0:
            raise pylon.RUNTIME_EXCEPTION("No camera present.")

        # Create an array of instant cameras for the found devices and avoid
        # exceeding a maximum number of devices.
        self.cameras = pylon.InstantCameraArray(
            min(len(self.devices), maxCamerasToUse))
Esempio n. 4
0
    def disable_chunks(self):
        # Disable chunk mode.
        if genicam.IsWritable(self.camera.ChunkModeActive):
            self.camera.ChunkModeActive = False
        else:
            raise pylon.RUNTIME_EXCEPTION(
                "The camera doesn't support chunk features")

        self.camera.ChunkSelector = "Timestamp"
        self.camera.ChunkEnable = False

        self.camera.ChunkSelector = "CounterValue"
        self.camera.ChunkEnable = False

        self.camera.ChunkSelector = "ExposureTime"
        self.camera.ChunkEnable = False

        self.camera.ChunkSelector = "PayloadCRC16"
        self.camera.ChunkEnable = False
    def __init__(self):
        # converting to opencv bgr format (it's needed for displaying the image)
        self.converter = pylon.ImageFormatConverter()
        self.converter.OutputPixelFormat = pylon.PixelType_BGR8packed
        self.converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned

        tlFactory = pylon.TlFactory.GetInstance()
        devices = tlFactory.EnumerateDevices()
        if len(devices) == 0:
            raise pylon.RUNTIME_EXCEPTION("No camera present.")

        cameras = pylon.InstantCameraArray(2)

        for i, camera in enumerate(cameras):
            camera.Attach(tlFactory.CreateDevice(devices[i]))

        self.cameras = cameras
        self.cameras.Open()

        self.script_path = os.path.dirname(os.path.abspath(__file__))
        os.chdir(self.script_path)
Esempio n. 6
0
    def __init__(self, register_event_listener=False, my_events=None):
        tlFactory = pylon.TlFactory.GetInstance()
        # Get all attached devices and raise an error if no devices found
        devices = tlFactory.EnumerateDevices()
        if not devices:
            raise pylon.RUNTIME_EXCEPTION("No camera present.")

        # Create an array of instant cameras for the found devices and avoid
        # exceeding a maximum number of devices.
        self.cameras = pylon.InstantCameraArray(min(len(devices), MAX_CAMERAS))

        # Create and attach all Pylon Devices.
        for i, cam in enumerate(self.cameras):
            cam.Attach(tlFactory.CreateDevice(devices[i]))
            cam.RegisterConfiguration(my_events, pylon.RegistrationMode_Append,
                                      pylon.Cleanup_Delete)
            # Print the model name of the camera.
            logger.info("Initalizing device : {}".format(
                cam.GetDeviceInfo().GetModelName()))
            if "NIR" in cam.GetDeviceInfo().GetModelName().upper()[-3:]:
                self.nir = self.cameras[i]
            else:
                self.rgb = self.cameras[i]
Esempio n. 7
0
    def enable_chunks(self):
        """Meta data is delivered within the frame as a chunks."""
        # Enable chunks in general.
        if genicam.IsWritable(self.camera.ChunkModeActive):
            self.camera.ChunkModeActive = True
        else:
            raise pylon.RUNTIME_EXCEPTION(
                "The camera doesn't support chunk features")

        # Enable time stamp chunks.
        self.camera.ChunkSelector = "Timestamp"
        self.camera.ChunkEnable = True

        # Enable counter chunks
        self.camera.ChunkSelector = "CounterValue"
        self.camera.ChunkEnable = True

        # Enable exposure time chunk
        self.camera.ChunkSelector = "ExposureTime"
        self.camera.ChunkEnable = True

        # Enable CRC checksum chunks.
        self.camera.ChunkSelector = "PayloadCRC16"
        self.camera.ChunkEnable = True
Esempio n. 8
0
import numpy as np
import scipy.misc
import cv2

# preface
exitCode = 0
maxCamerasToUse = 4
countOfImagesToGrab = 1
try:

    # get the transport layer factory
    tlFactory = pylon.TlFactory.GetInstance()

    devices = tlFactory.EnumerateDevices()
    if len(devices) == 0:
        raise pylon.RUNTIME_EXCEPTION("No camera present")

    cameras = pylon.InstantCameraArray(min(len(devices), maxCamerasToUse))

    for ii, cam in enumerate(cameras):
        cam.Attach(tlFactory.CreateDevice(devices[ii]))

        print(cam.GetDeviceInfo().GetModelName(), "-",
              cam.GetDeviceInfo().GetSerialNumber())

        # set parameters
        # pixel format
        print(cam.PixelFormat.GetValue())
        cam.PixelFormat.SetValue("Mono12")
        print(cam.PixelFormat.GetValue())
        # exposure time
Esempio n. 9
0
    # Open the camera.
    camera.Open()

    # A GenICam node map is required for accessing chunk data. That's why a small node map is required for each grab result.
    # Creating a node map can be time consuming, because node maps are created by parsing an XML description file.
    # The node maps are usually created dynamically when StartGrabbing() is called.
    # To avoid a delay caused by node map creation in StartGrabbing() you have the option to create
    # a static pool of node maps once before grabbing.
    camera.StaticChunkNodeMapPoolSize = camera.MaxNumBuffer.GetValue()

    # Enable chunks in general.
    if genicam.IsWritable(camera.ChunkModeActive):
        camera.ChunkModeActive = True
    else:
        raise pylon.RUNTIME_EXCEPTION("The camera doesn't support chunk features")

    # Enable time stamp chunks.
    camera.ChunkSelector = "Timestamp"
    camera.ChunkEnable = True

    if not camera.IsUsb():
        # Enable frame counter chunks.
        camera.ChunkSelector = "Framecounter"
        camera.ChunkEnable = True

    # Enable CRC checksum chunks.
    camera.ChunkSelector = "PayloadCRC16"
    camera.ChunkEnable = True

    # Start the grabbing of c_countOfImagesToGrab images.
Esempio n. 10
0
def parameterize_cameras(number_of_cameras, list_of_setting_lists):
    '''
    Int: number_of_cameras, number of cameras attached to computer
    
    List: list_of_setting_lists, [[pixel_format, exposure, gain, fps],[...], ... ,[...]] sets capture parameters for each camera
    must have the same number of sub-lists as 'number_of_cameras' 
    sublists must have the format of [pixel_format, exposure, gain, fps]
    
    '''

    #Get the transport layer factory.
    tlFactory = pylon.TlFactory.GetInstance()

    #Get all attached devices and exit application if no device is found.
    devices = tlFactory.EnumerateDevices()
    if len(devices) == 0:
        raise pylon.RUNTIME_EXCEPTION("No camera present.")

    #Create an array of instant cameras for the found devices and avoid exceeding a maximum number of devices.
    cameras = pylon.InstantCameraArray(min(len(devices), number_of_cameras))
    #l = cameras.GetSize()
    try:
        for i, cam in enumerate(cameras):

            a = list_of_setting_lists[i]
            pixel_format = a[0]
            exposure = a[1]
            gain = a[2]
            fps = a[3]

            cam.Attach(tlFactory.CreateDevice(devices[i]))

            cam.Open()

            print('camera ' + str(i) + ' model name')
            cam_info = cam.GetDeviceInfo().GetModelName(
            ), "-", cam.GetDeviceInfo().GetSerialNumber()
            cam_info = cam_info[0] + cam_info[1] + cam_info[2]
            print(cam_info)

            cam.PixelFormat.SetValue(pixel_format)
            cam.ExposureTime.SetValue(exposure)
            cam.Gain.SetValue(gain)
            cam.AcquisitionFrameRateEnable.SetValue(True)
            cam.AcquisitionFrameRate.SetValue(fps)

            print('pixel format, exposure, gain, fps')
            spec = pixel_format + ', ' + str(exposure) + ', ' + str(
                gain) + ', ' + str(fps)
            print(spec)
            print('resulting frame rate')
            cam_info = str(cam.ResultingFrameRate.GetValue())
            print(cam_info)

            # Print the model name of the camera.
            cam_info = cam.GetDeviceInfo().GetModelName()
            cam.Close()
    except genicam.GenericException as e:
        # Error handling
        print("An exception occurred.", str(e))
        cameras.Close()

    return cameras