# 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. if cam.get_node_map().is_available("ChunkModeActive"): cam.get_node_map()["ChunkModeActive"] = True else: raise Exception("The camera doesn't support chunk features") counter = 0 #Enable time stamp chunks. cam.get_node_map()['ChunkSelector'] = "Timestamp" cam.get_node_map()['ChunkEnable'] = True cam.get_node_map()['ChunkSelector'] = "PayloadCRC16" cam.get_node_map()['ChunkEnable'] = True cam.start_grabbing(5) grabResult = BaslerUsbGrabResult() while cam.is_grabbing(): cam.retrieve_result(500, grabResult) print("GrabSucceeded: " + str(grabResult.grab_succeeded())) print("SizeX: " + str(grabResult.width)) print("SizeY: " + str(grabResult.height)) ###need to implment mroe method here cam.get_node_map()["ChunkModeActive"] = True #to release resource, this function must be called factory_instant.terminate()
if cam.get_node_map().is_available("EventSelector"): #Enable the sending of Exposure End events. # Select the event to be received. cam.get_node_map()["EventSelector"] = "ExposureEnd" cam.get_node_map()["EventNotification"] = "On" #Enable the sending of Frame Start Overtrigger events. if cam.get_node_map().is_available("FrameStartOvertrigger"): cam.get_node_map()["EventSelector"] = "FrameStartOvertrigger" cam.get_node_map()["EventNotification"] = "On" #Start the grabbing of c_countOfImagesToGrab images. # The camera device is parameterized with a default configuration which # sets up free-running continuous acquisition. grabResult = BaslerUsbGrabResult() counter = 0 cam.start_grabbing(5) #Camera.StopGrabbing() is called automatically by the RetrieveResult() method # when c_countOfImagesToGrab images have been retrieved. while cam.is_grabbing(): #Retrieve grab results and notify the camera event and image event handlers. cam.retrieve_result(500, grabResult) #Nothing to do here with the grab result, the grab results are handled by the registered event handlers. #Disable the sending of Exposure End events. cam.get_node_map()["EventSelector"] = "ExposureEnd" cam.get_node_map()["EventNotification"] = "Off" #Disable the sending of Frame Start Overtrigger events.
#advance on Frame End to initial set, cam.get_node_map( )["SequencerSetNext"] = curSet + incSet #terminates sequence definition #full height cam.get_node_map( )["Height"] = cam.get_node_map().get_node("Height").inc * (increments) cam.get_node_map().get_node("SequencerSetSave").execute() # Enable the sequencer feature. # From here on you cannot change the sequencer settings anymore. cam.get_node_map()["SequencerConfigurationMode"] = "Off" cam.get_node_map()["SequencerMode"] = "On" # Start the grabbing of images. grabResult = BaslerUsbGrabResult() counter = 0 cam.start_grabbing(5) #Camera.StopGrabbing() is called automatically by the RetrieveResult() method # when c_countOfImagesToGrab images have been retrieved. while cam.is_grabbing(): if (cam.wait_for_frame_trigger_ready( 500, enum.TimeoutHandling_ThrowException)): cam.execute_software_trigger() cam.retrieve_result(500, grabResult) if grabResult.grab_succeeded(): counter = counter + 1 print("SizeX: " + str(grabResult.width)) print("SizeY: " + str(grabResult.height)) grabResult.save_image(enum.ImageFileFormat_Bmp,
cam = BaslerUsbInstantCamera.BaslerUsbInstantCamera.create_cam( factory_instant.create_first_device()) print("Using device " + cam.device_info.model_name) # The parameter MaxNumBuffer can be used to control the count of buffers # allocated for grabbing. The default value of this parameter is 10. cam.get_node_map()["MaxNumBuffer"] = 5 #Start the grabbing of c_countOfImagesToGrab images. # The camera device is parameterized with a default configuration which # sets up free-running continuous acquisition. cam.open() cam.start_grabbing(countOfImagesToGrab) grabResult = BaslerUsbGrabResult() #Camera.StopGrabbing() is called automatically by the RetrieveResult() method # when c_countOfImagesToGrab images have been retrieved. while cam.is_grabbing(): cam.retrieve_result(500, grabResult) if grabResult.grab_succeeded(): #grabResult.save_image(ImageFileFormat_Bmp, str(counter) + "your_file.bmp") print("SizeX: " + str(grabResult.width)) print("SizeY: " + str(grabResult.height)) else: print("Error: " + grabResult.error_code + " " + grabResult.error_description) except: traceback.print_exc(file=sys.stdout)
def AutoWhiteBalance(cam): # Check whether the Balance White Auto feature is available. if not cam.get_node_map().is_writable("BalanceWhiteAuto"): print("The camera does not support Balance White Auto.") return # Maximize the grabbed image area of interest (Image AOI). if cam.get_node_map().is_writable("OffsetX"): cam.get_node_map()["OffsetX"] = cam.get_node_map().get_node( "OffsetX").min if cam.get_node_map().is_writable("OffsetY"): cam.get_node_map()["OffsetY"] = cam.get_node_map().get_node( "OffsetY").min cam.get_node_map()["Width"] = cam.get_node_map().get_node("Width").max cam.get_node_map()["Height"] = cam.get_node_map().get_node("Height").max if cam.get_node_map().is_available("AutoFunctionROISelector"): # Set the Auto Function ROI for luminance statistics. # We want to use ROI2 for gathering the statistics cam.get_node_map()["AutoFunctionROISelector"] = "ROI1" cam.get_node_map( )["AutoFunctionROIUseBrightness"] = False # ROI 1 is used for brightness control cam.get_node_map()["AutoFunctionROISelector"] = "ROI2" cam.get_node_map( )["AutoFunctionROIUseBrightness"] = True # ROI 2 is not used for brightness control # Set the Auto Function AOI for white balance statistics. # Currently, AutoFunctionROISelector_ROI2 is predefined to gather # white balance statistics. cam.get_node_map( )["AutoFunctionROISelector"] = "ROI2" # configure ROI 1 cam.get_node_map()["AutoFunctionROIOffsetX"] = 0 cam.get_node_map()["AutoFunctionROIOffsetY"] = 0 cam.get_node_map()["AutoFunctionROIWidth"] = cam.get_node_map( ).get_node("Width").max cam.get_node_map()["AutoFunctionROIHeight"] = cam.get_node_map( ).get_node("Height").max print("Trying 'BalanceWhiteAuto = Once'.") print("Initial balance ratio: ") cam.get_node_map()["BalanceRatioSelector"] = "Red" print("R = " + str(cam.get_node_map()["BalanceRatio"])) cam.get_node_map()["BalanceRatioSelector"] = "Green" print("G = " + str(cam.get_node_map()["BalanceRatio"])) cam.get_node_map()["BalanceRatioSelector"] = "Blue" print("B = " + str(cam.get_node_map()["BalanceRatio"])) cam.get_node_map()["BalanceWhiteAuto"] = "Once" # When the "once" mode of operation is selected, # the parameter values are automatically adjusted until the related image property # reaches the target value. After the automatic parameter value adjustment is complete, the auto # function will automatically be set to "off" and the new parameter value will be applied to the # subsequently grabbed images. n = 0 while cam.get_node_map()["BalanceWhiteAuto"] == "Off": grabResult = BaslerUsbGrabResult() cam.grab_one(5000, grabResult) PyWaitObject.sleep(1000) n += 1 if n > 100: raise Exception( "The adjustment of auto white balance did not finish.") print("BalanceWhiteAuto went back to 'Off' after " + str(n) + " frames") print("Final balance ratio: ") cam.get_node_map()["BalanceRatioSelector"] = "Red" print("R = " + str(cam.get_node_map()["BalanceRatio"])) cam.get_node_map()["BalanceRatioSelector"] = "Green" print("G = " + str(cam.get_node_map()["BalanceRatio"])) cam.get_node_map()["BalanceRatioSelector"] = "Blue" print("B = " + str(cam.get_node_map()["BalanceRatio"]))
def AutoGainOnce(cam): #Check whether the gain auto function is available if not cam.get_node_map().is_writable("GainAuto"): print("The camera does not support Gain Auto.") return #Maximize the grabbed image area of interest (Image AOI). if cam.get_node_map().is_writable("OffsetX"): cam.get_node_map()["OffsetX"] = cam.get_node_map().get_node( "OffsetX").min if cam.get_node_map().is_writable("OffsetY"): cam.get_node_map()["OffsetY"] = cam.get_node_map().get_node( "OffsetY").min cam.get_node_map()["Width"] = cam.get_node_map().get_node("Width").max cam.get_node_map()["Height"] = cam.get_node_map().get_node("Height").max if cam.get_node_map().is_available("AutoFunctionROISelector"): # Set the Auto Function ROI for luminance statistics. #We want to use ROI1 for gathering the statistics cam.get_node_map()["AutoFunctionROISelector"] = "ROI1" cam.get_node_map( )["AutoFunctionROIUseBrightness"] = True #ROI 1 is used for brightness control cam.get_node_map()["AutoFunctionROISelector"] = "ROI2" cam.get_node_map( )["AutoFunctionROIUseBrightness"] = False #ROI 2 is not used for brightness control #Set the ROI (in this example the complete sensor is used) cam.get_node_map( )["AutoFunctionROISelector"] = "ROI1" # configure ROI 1 cam.get_node_map()["AutoFunctionROIOffsetX"] = 0 cam.get_node_map()["AutoFunctionROIOffsetY"] = 0 cam.get_node_map()["AutoFunctionROIWidth"] = cam.get_node_map( ).get_node("Width").max cam.get_node_map()["AutoFunctionROIHeight"] = cam.get_node_map( ).get_node("Height").max #Set the target value for luminance control. # A value of 0.3 means that the target brightness is 30 % of the maximum brightness of the raw pixel value read out from the sensor. # A value of 0.4 means 40 % and so forth. cam.get_node_map()["AutoTargetBrightness"] = 0.3 #We are going to try GainAuto = Once. print("Trying 'GainAuto = Once'.") print("Initial Gain = " + str(cam.get_node_map()["Gain"])) #Set the gain ranges for luminance control. cam.get_node_map()["AutoGainLowerLimit"] = cam.get_node_map().get_node( "Gain").min cam.get_node_map()["AutoGainUpperLimit"] = cam.get_node_map().get_node( "Gain").max cam.get_node_map()["GainAuto"] = "Once" #When the "once" mode of operation is selected, # the parameter values are automatically adjusted until the related image property # reaches the target value. After the automatic parameter value adjustment is complete, the auto # function will automatically be set to "off" and the new parameter value will be applied to the # subsequently grabbed images. n = 0 while cam.get_node_map()["GainAuto"] == "Off": grabResult = BaslerUsbGrabResult() cam.grab_one(5000, grabResult) PyWaitObject.sleep(1000) n += 1 if n > 100: raise Exception("The adjustment of auto gain did not finish.") print("GainAuto went back to 'Off' after ") print("Initial Gain = " + str(cam.get_node_map()["Gain"]))
def AutoExposureContinuous(cam): # Check whether the ExposureAuto function is available if not cam.get_node_map().is_writable("ExposureAuto"): print("The camera does not support ExposureAuto.") return # Maximize the grabbed image area of interest (Image AOI). if cam.get_node_map().is_writable("OffsetX"): cam.get_node_map()["OffsetX"] = cam.get_node_map().get_node( "OffsetX").min if cam.get_node_map().is_writable("OffsetY"): cam.get_node_map()["OffsetY"] = cam.get_node_map().get_node( "OffsetY").min cam.get_node_map()["Width"] = cam.get_node_map().get_node("Width").max cam.get_node_map()["Height"] = cam.get_node_map().get_node("Height").max if cam.get_node_map().is_available("AutoFunctionROISelector"): # Set the Auto Function ROI for luminance statistics. # We want to use ROI1 for gathering the statistics cam.get_node_map()["AutoFunctionROISelector"] = "ROI1" cam.get_node_map( )["AutoFunctionROIUseBrightness"] = True # ROI 1 is used for brightness control cam.get_node_map()["AutoFunctionROISelector"] = "ROI2" cam.get_node_map( )["AutoFunctionROIUseBrightness"] = False # ROI 2 is not used for brightness control # Set the ROI (in this example the complete sensor is used) cam.get_node_map( )["AutoFunctionROISelector"] = "ROI1" # configure ROI 1 cam.get_node_map()["AutoFunctionROIOffsetX"] = 0 cam.get_node_map()["AutoFunctionROIOffsetY"] = 0 cam.get_node_map()["AutoFunctionROIWidth"] = cam.get_node_map( ).get_node("Width").max cam.get_node_map()["AutoFunctionROIHeight"] = cam.get_node_map( ).get_node("Height").max # Set the target value for luminance control. # A value of 0.3 means that the target brightness is 30 % of the maximum brightness of the raw pixel value read out from the sensor. # A value of 0.4 means 40 % and so forth. cam.get_node_map()["AutoTargetBrightness"] = 0.3 # We are going to try GainAuto = Continuous. print("ExposureAuto 'GainAuto = Continuous'.") print("Initial exposure time = " + str(cam.get_node_map()["ExposureTime"])) cam.get_node_map()["ExposureAuto"] = "Continuous" #When "continuous" mode is selected, the parameter value is adjusted repeatedly while images are acquired. # Depending on the current frame rate, the automatic adjustments will usually be carried out for # every or every other image, unless the cameras microcontroller is kept busy by other tasks. # The repeated automatic adjustment will proceed until the "once" mode of operation is used or # until the auto function is set to "off", in which case the parameter value resulting from the latest # automatic adjustment will operate unless the value is manually adjusted. # For demonstration purposes, we will use only 20 images. for i in range(20): grabResult = BaslerUsbGrabResult() cam.grab_one(5000, grabResult) PyWaitObject.sleep(1000) cam.get_node_map()["ExposureAuto"] = "Off" print("Final exposure time = " + str(cam.get_node_map()["ExposureTime"]))