def __init__(self, camera_id = None, parameters = None, **kwds): super().__init__(**kwds) self.cur_offsetx = None self.cur_offsety = None self.old_offsetx = None self.old_offsety = None self.max_offsetx = None self.max_offsety = None self.n_analyzed = 0 self.n_dropped = 0 self.start_time = None self.params_mutex = QtCore.QMutex() self.running = False self.zero_dist = parameters.get("zero_dist") # Initialize library. spinnaker.pySpinInitialize(verbose = False) # Get the camera & set some defaults. self.camera = spinnaker.getCamera(camera_id) # Only Grasshopper has defect correction if self.camera.hasProperty("VideoMode"): self.camera.setProperty("VideoMode", parameters.get("video_mode")) self.camera.setProperty("pgrDefectPixelCorrectionEnable", False)
def __init__(self, config=None, is_master=False, **kwds): kwds["config"] = config super().__init__(**kwds) self.is_master = is_master # The camera functionality. self.camera_functionality = cameraFunctionality.CameraFunctionality( camera_name=self.camera_name, is_master=self.is_master, parameters=self.parameters) # Initialize library. spinnaker.pySpinInitialize(verbose=False) # Get the camera & set some defaults. self.camera = spinnaker.getCamera(config.get("camera_id")) # Set FLIR-specific camera properties to control relationship between # exposure time and frame rate: This dictionary will allow extension in the future if needed self.exposure_control = {"CameraControlExposure": True} # Extract preset values if provided if config.has("presets"): # Extract preset values presets = config.get("presets") print("Configuring preset values of spinnaker camera: " + str(config.get("camera_id"))) # Loop over values and set them for p_name in presets.getAttrs(): if self.camera.hasProperty( p_name ): # Confirm the camera has the property and warn if not p_value = presets.get(p_name) self.camera.setProperty(p_name, p_value) # Set value set_value = self.camera.getProperty( p_name).getValue() # Check set print(" " + str(p_name) + ": " + str(p_value) + " (" + str(set_value) + ")") else: if p_name not in self.exposure_control.keys(): print("!!!! preset " + str(p_name) + " is not a valid parameter for this camera") # Set the exposure-frame-rate-control parameters self.exposure_control["CameraControlExposure"] = presets.get( "CameraControlExposure", True) print("Set exposure control properties:") for key in self.exposure_control.keys(): print(" " + str(key) + ": " + str(self.exposure_control[key])) else: print("No presets provided for spinnaker camera: " + str(config.get("camera_id"))) # Verify that we have turned off some of these 'features'. ## REMOVED THIS BLOCK AS IT IS CAMERA SPECIFIC #for feature in ["pgrDefectPixelCorrectionEnable", # "BlackLevelClampingEnable", # "SharpnessEnabled", # "GammaEnabled"]: # if self.camera.hasProperty(feature): # assert not self.camera.getProperty(feature).getValue() # Configure 'master' cameras to not use triggering. # self.camera.getProperty("TriggerMode") if self.is_master: self.camera.setProperty("TriggerMode", "Off") # This line is connected to the DAQ. self.camera.setProperty("LineSelector", "Line1") self.camera.setProperty("LineSource", "ExposureActive") # This line is connected to the other cameras. self.camera.setProperty("LineSelector", "Line2") self.camera.setProperty("LineMode", "Output") self.camera.setProperty("LineSource", "ExposureActive") # Configure 'slave' cameras to use triggering. # We are following: http://www.ptgrey.com/KB/11052 # # "Configuring Synchronized Capture with Multiple Cameras" # # Also, we connected the master camera to the DAQ card # using it's OPTO-OUT connection. # else: self.camera.setProperty("TriggerMode", "On") self.camera.setProperty("TriggerSource", "Line3") self.camera.setProperty("TriggerOverlap", "ReadOut") self.camera.setProperty( "TriggerActivation", config.get("trigger_activation", "FallingEdge")) # # Dictionary of Point Grey specific camera parameters. # # All cameras can set these. self.pgrey_props = { "BlackLevel": True, "Gain": True, "Height": True, "OffsetX": True, "OffsetY": True, "Width": True } # Only master cameras can set "AcquisitionFrameRate". if self.is_master: self.pgrey_props["AcquisitionFrameRate"] = True # # FIXME: We're using a made up max_value for this parameter because it is # the default parameter. If we use the real range then any # parameters that are added later could have their frame rate # changed in an unexpected way. Unfortunately this also means that # if the user goes above the real maximum on this parameter then # the software will crash. # self.parameters.add( params.ParameterRangeFloat( description="Acquisition frame rate (FPS)", name="AcquisitionFrameRate", value=10.0, max_value=5000, min_value=self.camera.getProperty( "AcquisitionFrameRate").getMinimum())) # Slave cameras can set "ExposureTime". # # FIXME? If this is too large then the slave will be taking images # at a different rate than master. Maybe this should be # limited? Automatically set based on "master" frame rate? # else: self.pgrey_props["ExposureTime"] = True self.parameters.add( params.ParameterRangeFloat(description="Exposure time (us)", name="ExposureTime", value=99800.0, max_value=self.camera.getProperty( "ExposureTime").getMaximum(), min_value=self.camera.getProperty( "ExposureTime").getMinimum())) # Load properties as required by the spinnaker Python wrapper. for pname in self.pgrey_props: self.camera.getProperty(pname) max_intensity = 2**12 self.parameters.setv("max_intensity", max_intensity) # Set chip size and HAL parameter ranges. x_chip = self.camera.getProperty("WidthMax").getValue() self.parameters.setv("x_chip", x_chip) for pname in ["x_end", "x_start"]: self.parameters.getp(pname).setMaximum(x_chip) y_chip = self.camera.getProperty("HeightMax").getValue() self.parameters.setv("y_chip", y_chip) for pname in ["y_end", "y_start"]: self.parameters.getp(pname).setMaximum(y_chip) # # Reset X, Y offsets. We do this here because otherwise the # initial ranges of these parameters will be incorrect and the # only way to fix them is using the parameters editor. # self.camera.setProperty("OffsetX", 0) self.camera.setProperty("OffsetY", 0) self.parameters.add( params.ParameterRangeFloat( description="Black level", name="BlackLevel", value=1.0, max_value=self.camera.getProperty("BlackLevel").getMaximum(), min_value=self.camera.getProperty("BlackLevel").getMinimum())) self.parameters.add( params.ParameterRangeFloat( description="Gain", name="Gain", value=10.0, max_value=self.camera.getProperty("Gain").getMaximum(), min_value=self.camera.getProperty("Gain").getMinimum())) self.parameters.add( params.ParameterRangeInt(description="AOI height", name="Height", value=y_chip, max_value=y_chip, min_value=4)) self.parameters.add( params.ParameterRangeInt(description="AOI x offset", name="OffsetX", value=0, max_value=x_chip - 4, min_value=0)) self.parameters.add( params.ParameterRangeInt(description="AOI y offset", name="OffsetY", value=0, max_value=y_chip - 4, min_value=0)) self.parameters.add( params.ParameterRangeInt(description="AOI width", name="Width", value=x_chip, max_value=x_chip, min_value=4)) # Disable editing of the HAL versions of these parameters. for param in [ "exposure_time", "x_bin", "x_end", "x_start", "y_end", "y_start", "y_bin" ]: self.parameters.getp(param).setMutable(False) self.newParameters(self.parameters, initialization=True)
def __init__(self, config=None, is_master=False, **kwds): kwds["config"] = config super().__init__(**kwds) self.is_master = is_master # The camera functionality. self.camera_functionality = cameraFunctionality.CameraFunctionality( camera_name=self.camera_name, is_master=self.is_master, parameters=self.parameters) # Initialize library. spinnaker.pySpinInitialize(verbose=False) # Get the camera & set some defaults. self.camera = spinnaker.getCamera(config.get("camera_id")) # In order to turn off pixel defect correction the camera has # to be in video mode 0. self.camera.setProperty("VideoMode", "Mode0") self.camera.setProperty("pgrDefectPixelCorrectionEnable", False) # Set pixel format. #self.camera.setProperty("PixelFormat", "Mono12Packed") #self.camera.setProperty("PixelFormat", "Mono12p") self.camera.setProperty("PixelFormat", "Mono16") self.camera.setProperty("VideoMode", config.get("video_mode")) # We don't want any of these 'features'. self.camera.setProperty("AcquisitionFrameRateAuto", "Off") self.camera.setProperty("ExposureAuto", "Off") self.camera.setProperty("GainAuto", "Off") if self.camera.hasProperty("pgrExposureCompensationAuto"): self.camera.setProperty("pgrExposureCompensationAuto", "Off") if self.camera.hasProperty("BlackLevelClampingEnable"): self.camera.setProperty("BlackLevelClampingEnable", False) if self.camera.hasProperty("SharpnessEnabled"): self.camera.setProperty("SharpnessEnabled", False) if self.camera.hasProperty("GammaEnabled"): self.camera.setProperty("GammaEnabled", False) # # No idea what this means in the context of a black and white # camera. We try and turn it off but that seems to be much # harder to do than one would hope. # self.camera.setProperty("OnBoardColorProcessEnabled", False) # Verify that we have turned off some of these 'features'. for feature in [ "pgrDefectPixelCorrectionEnable", "BlackLevelClampingEnable", "SharpnessEnabled", "GammaEnabled" ]: if self.camera.hasProperty(feature): assert not self.camera.getProperty(feature).getValue() # Configure 'master' cameras to not use triggering. # self.camera.getProperty("TriggerMode") if self.is_master: self.camera.setProperty("TriggerMode", "Off") # This line is connected to the DAQ. self.camera.setProperty("LineSelector", "Line1") self.camera.setProperty("LineSource", "ExposureActive") # This line is connected to the other cameras. self.camera.setProperty("LineSelector", "Line2") self.camera.setProperty("LineMode", "Output") self.camera.setProperty("LineSource", "ExposureActive") # Configure 'slave' cameras to use triggering. # # We are following: http://www.ptgrey.com/KB/11052 # "Configuring Synchronized Capture with Multiple Cameras" # # Also, we connected the master camera to the DAQ card # using it's OPTO-OUT connection. # else: self.camera.setProperty("TriggerMode", "On") self.camera.setProperty("TriggerSource", "Line3") self.camera.setProperty("TriggerOverlap", "ReadOut") self.camera.setProperty( "TriggerActivation", config.get("trigger_activation", "FallingEdge")) # # Dictionary of Point Grey specific camera parameters. # # All cameras can set these. self.pgrey_props = { "BlackLevel": True, "Gain": True, "Height": True, "OffsetX": True, "OffsetY": True, "Width": True } # Only master cameras can set "AcquisitionFrameRate". if self.is_master: self.pgrey_props["AcquisitionFrameRate"] = True # # FIXME: We're using a made up max_value for this parameter because it is # the default parameter. If we use the real range then any # parameters that are added later could have their frame rate # changed in an unexpected way. Unfortunately this also means that # if the user goes above the real maximum on this parameter then # the software will crash. # self.parameters.add( params.ParameterRangeFloat( description="Acquisition frame rate (FPS)", name="AcquisitionFrameRate", value=10.0, max_value=500.0, min_value=self.camera.getProperty( "AcquisitionFrameRate").getMinimum())) # Slave cameras can set "ExposureTime". # # FIXME? If this is too large then the slave will be taking images # at a different rate than master. Maybe this should be # limited? Automatically set based on "master" frame rate? # else: self.pgrey_props["ExposureTime"] = True self.parameters.add( params.ParameterRangeFloat(description="Exposure time (us)", name="ExposureTime", value=99800.0, max_value=self.camera.getProperty( "ExposureTime").getMaximum(), min_value=self.camera.getProperty( "ExposureTime").getMinimum())) # Load properties as required by the spinnaker Python wrapper. for pname in self.pgrey_props: self.camera.getProperty(pname) max_intensity = 2**12 self.parameters.setv("max_intensity", max_intensity) # Set chip size and HAL parameter ranges. x_chip = self.camera.getProperty("WidthMax").getValue() self.parameters.setv("x_chip", x_chip) for pname in ["x_end", "x_start"]: self.parameters.getp(pname).setMaximum(x_chip) y_chip = self.camera.getProperty("HeightMax").getValue() self.parameters.setv("y_chip", y_chip) for pname in ["y_end", "y_start"]: self.parameters.getp(pname).setMaximum(y_chip) # # Reset X, Y offsets. We do this here because otherwise the # initial ranges of these parameters will be incorrect and the # only way to fix them is using the parameters editor. # self.camera.setProperty("OffsetX", 0) self.camera.setProperty("OffsetY", 0) self.parameters.add( params.ParameterRangeFloat( description="Black level", name="BlackLevel", value=1.0, max_value=self.camera.getProperty("BlackLevel").getMaximum(), min_value=self.camera.getProperty("BlackLevel").getMinimum())) self.parameters.add( params.ParameterRangeFloat( description="Gain", name="Gain", value=10.0, max_value=self.camera.getProperty("Gain").getMaximum(), min_value=self.camera.getProperty("Gain").getMinimum())) self.parameters.add( params.ParameterRangeInt(description="AOI height", name="Height", value=y_chip, max_value=y_chip, min_value=4)) self.parameters.add( params.ParameterRangeInt(description="AOI x offset", name="OffsetX", value=0, max_value=x_chip - 4, min_value=0)) self.parameters.add( params.ParameterRangeInt(description="AOI y offset", name="OffsetY", value=0, max_value=y_chip - 4, min_value=0)) self.parameters.add( params.ParameterRangeInt(description="AOI width", name="Width", value=x_chip, max_value=x_chip, min_value=4)) # Disable editing of the HAL versions of these parameters. for param in [ "exposure_time", "x_bin", "x_end", "x_start", "y_end", "y_start", "y_bin" ]: self.parameters.getp(param).setMutable(False) self.newParameters(self.parameters, initialization=True)
def __init__(self, camera_id=None, parameters=None, **kwds): super().__init__(**kwds) self.cur_offsetx = None self.cur_offsety = None self.old_offsetx = None self.old_offsety = None self.max_offsetx = None self.max_offsety = None self.n_analyzed = 0 self.n_dropped = 0 self.start_time = None self.params_mutex = QtCore.QMutex() self.running = False self.zero_dist = parameters.get("zero_dist") # Initialize library. spinnaker.pySpinInitialize(verbose=False) # Get the camera & set some defaults. self.camera = spinnaker.getCamera(camera_id) # In order to turn off pixel defect correction the camera has # to be in video mode 0. self.camera.setProperty("VideoMode", "Mode0") self.camera.setProperty("pgrDefectPixelCorrectionEnable", False) # Set pixel format. self.camera.setProperty("PixelFormat", "Mono16") self.camera.setProperty("VideoMode", parameters.get("video_mode")) # We don't want any of these 'features'. self.camera.setProperty("AcquisitionFrameRateAuto", "Off") self.camera.setProperty("ExposureAuto", "Off") self.camera.setProperty("GainAuto", "Off") if self.camera.hasProperty("pgrExposureCompensationAuto"): self.camera.setProperty("pgrExposureCompensationAuto", "Off") if self.camera.hasProperty("BlackLevelClampingEnable"): self.camera.setProperty("BlackLevelClampingEnable", False) if self.camera.hasProperty("SharpnessEnabled"): self.camera.setProperty("SharpnessEnabled", False) if self.camera.hasProperty("GammaEnabled"): self.camera.setProperty("GammaEnabled", False) # # No idea what this means in the context of a black and white # camera. We try and turn it off but that seems to be much # harder to do than one would hope. # self.camera.setProperty("OnBoardColorProcessEnabled", False) # Verify that we have turned off some of these 'features'. for feature in [ "pgrDefectPixelCorrectionEnable", "BlackLevelClampingEnable", "SharpnessEnabled", "GammaEnabled" ]: if self.camera.hasProperty(feature): assert not self.camera.getProperty(feature).getValue() # Configure camera to not use triggering. # self.camera.setProperty("TriggerMode", "Off") # Configure acquisition parameters. # # Note: The order is important here. # for pname in [ "BlackLevel", "Gain", "Height", "Width", "OffsetX", "OffsetY", "AcquisitionFrameRate" ]: self.camera.setProperty(pname, parameters.get(pname)) # Use maximum exposure time allowed by desired frame rate. # self.camera.setProperty( "ExposureTime", self.camera.getProperty("ExposureTime").getMaximum()) # Get current offsets. # self.cur_offsetx = self.camera.getProperty("OffsetX").getValue() self.cur_offsety = self.camera.getProperty("OffsetY").getValue() self.old_offsetx = self.cur_offsetx self.old_offsety = self.cur_offsety # Set maximum offsets. # self.max_offsetx = self.camera.getProperty("OffsetX").getMaximum() self.max_offsety = self.camera.getProperty("OffsetY").getMaximum()
def __init__(self, config = None, is_master = False, **kwds): kwds["config"] = config super().__init__(**kwds) self.is_master = is_master # The camera functionality. self.camera_functionality = cameraFunctionality.CameraFunctionality(camera_name = self.camera_name, is_master = self.is_master, parameters = self.parameters) # Initialize library. spinnaker.pySpinInitialize(verbose = False) # Get the camera & set some defaults. self.camera = spinnaker.getCamera(config.get("camera_id")) # In order to turn off pixel defect correction the camera has # to be in video mode 0. self.camera.setProperty("VideoMode", "Mode0") self.camera.setProperty("pgrDefectPixelCorrectionEnable", False) # Set pixel format. #self.camera.setProperty("PixelFormat", "Mono12Packed") #self.camera.setProperty("PixelFormat", "Mono12p") self.camera.setProperty("PixelFormat", "Mono16") self.camera.setProperty("VideoMode", config.get("video_mode")) # We don't want any of these 'features'. self.camera.setProperty("AcquisitionFrameRateAuto", "Off") self.camera.setProperty("ExposureAuto", "Off") self.camera.setProperty("GainAuto", "Off") if self.camera.hasProperty("pgrExposureCompensationAuto"): self.camera.setProperty("pgrExposureCompensationAuto", "Off") if self.camera.hasProperty("BlackLevelClampingEnable"): self.camera.setProperty("BlackLevelClampingEnable", False) if self.camera.hasProperty("SharpnessEnabled"): self.camera.setProperty("SharpnessEnabled", False) if self.camera.hasProperty("GammaEnabled"): self.camera.setProperty("GammaEnabled", False) # # No idea what this means in the context of a black and white # camera. We try and turn it off but that seems to be much # harder to do than one would hope. # self.camera.setProperty("OnBoardColorProcessEnabled", False) # Verify that we have turned off some of these 'features'. for feature in ["pgrDefectPixelCorrectionEnable", "BlackLevelClampingEnable", "SharpnessEnabled", "GammaEnabled"]: if self.camera.hasProperty(feature): assert not self.camera.getProperty(feature).getValue() # Configure 'master' cameras to not use triggering. # self.camera.getProperty("TriggerMode") if self.is_master: self.camera.setProperty("TriggerMode", "Off") # This line is connected to the DAQ. self.camera.setProperty("LineSelector", "Line1") self.camera.setProperty("LineSource", "ExposureActive") # This line is connected to the other cameras. self.camera.setProperty("LineSelector", "Line2") self.camera.setProperty("LineMode", "Output") self.camera.setProperty("LineSource", "ExposureActive") # Configure 'slave' cameras to use triggering. # # We are following: http://www.ptgrey.com/KB/11052 # "Configuring Synchronized Capture with Multiple Cameras" # # Also, we connected the master camera to the DAQ card # using it's OPTO-OUT connection. # else: self.camera.setProperty("TriggerMode", "On") self.camera.setProperty("TriggerSource", "Line3") self.camera.setProperty("TriggerOverlap", "ReadOut") # # Dictionary of Point Grey specific camera parameters. # # All cameras can set these. self.pgrey_props = {"BlackLevel" : True, "Gain" : True, "Height" : True, "OffsetX" : True, "OffsetY" : True, "Width" : True} # Only master cameras can set "AcquisitionFrameRate". if self.is_master: self.pgrey_props["AcquisitionFrameRate"] = True # # FIXME: We're using a made up max_value for this parameter because it is # the default parameter. If we use the real range then any # parameters that are added later could have their frame rate # changed in an unexpected way. Unfortunately this also means that # if the user goes above the real maximum on this parameter then # the software will crash. # self.parameters.add(params.ParameterRangeFloat(description = "Acquisition frame rate (FPS)", name = "AcquisitionFrameRate", value = 10.0, max_value = 500.0, min_value = self.camera.getProperty("AcquisitionFrameRate").getMinimum())) # Slave cameras can set "ExposureTime". # # FIXME? If this is too large then the slave will be taking images # at a different rate than master. Maybe this should be # limited? Automatically set based on "master" frame rate? # else: self.pgrey_props["ExposureTime"] = True self.parameters.add(params.ParameterRangeFloat(description = "Exposure time (us)", name = "ExposureTime", value = 99800.0, max_value = self.camera.getProperty("ExposureTime").getMaximum(), min_value = self.camera.getProperty("ExposureTime").getMinimum())) # Load properties as required by the spinnaker Python wrapper. for pname in self.pgrey_props: self.camera.getProperty(pname) max_intensity = 2**12 self.parameters.setv("max_intensity", max_intensity) # Set chip size and HAL parameter ranges. x_chip = self.camera.getProperty("WidthMax").getValue() self.parameters.setv("x_chip", x_chip) for pname in ["x_end", "x_start"]: self.parameters.getp(pname).setMaximum(x_chip) y_chip = self.camera.getProperty("HeightMax").getValue() self.parameters.setv("y_chip", y_chip) for pname in ["y_end", "y_start"]: self.parameters.getp(pname).setMaximum(y_chip) # # Reset X, Y offsets. We do this here because otherwise the # initial ranges of these parameters will be incorrect and the # only way to fix them is using the parameters editor. # self.camera.setProperty("OffsetX", 0) self.camera.setProperty("OffsetY", 0) self.parameters.add(params.ParameterRangeFloat(description = "Black level", name = "BlackLevel", value = 1.0, max_value = self.camera.getProperty("BlackLevel").getMaximum(), min_value = self.camera.getProperty("BlackLevel").getMinimum())) self.parameters.add(params.ParameterRangeFloat(description = "Gain", name = "Gain", value = 10.0, max_value = self.camera.getProperty("Gain").getMaximum(), min_value = self.camera.getProperty("Gain").getMinimum())) self.parameters.add(params.ParameterRangeInt(description = "AOI height", name = "Height", value = y_chip, max_value = y_chip, min_value = 4)) self.parameters.add(params.ParameterRangeInt(description = "AOI x offset", name = "OffsetX", value = 0, max_value = x_chip - 4, min_value = 0)) self.parameters.add(params.ParameterRangeInt(description = "AOI y offset", name = "OffsetY", value = 0, max_value = y_chip - 4, min_value = 0)) self.parameters.add(params.ParameterRangeInt(description = "AOI width", name = "Width", value = x_chip, max_value = x_chip, min_value = 4)) # Disable editing of the HAL versions of these parameters. for param in ["exposure_time", "x_bin", "x_end", "x_start", "y_end", "y_start", "y_bin"]: self.parameters.getp(param).setMutable(False) self.newParameters(self.parameters, initialization = True)