def max_ROI(camera): """ Set capture area to maximum available on the sensor. Arguments: camera : active camera object Returns: modified camera object """ try: # Maximize the Image AOI. if genicam.IsWritable(camera.OffsetX): camera.OffsetX = camera.OffsetX.Min if genicam.IsWritable(camera.OffsetY): camera.OffsetY = camera.OffsetY.Min camera.Width = camera.Width.Max camera.Height = camera.Height.Max except genicam.GenericException as e: raise genicam.RuntimeException("Could not apply configuration. GenICam::GenericException \ caught in OnOpened method msg=%s" % e.what()) return return camera
def set_parameters(self): """Basler camera parameters are accessed via NodeMap. Genicam interface is used to check if the nodes are writtable and then values are changed accordinly.""" node_map = self.camera.GetNodeMap() if genicam.IsWritable(node_map.GetNode("GainAuto")): self.camera.GainAuto = "Off" if genicam.IsWritable(node_map.GetNode("ExposureAuto")): self.camera.ExposureAuto = "Off" if genicam.IsWritable(node_map.GetNode("Width")): self.camera.Width = self.parameters['width'] if genicam.IsWritable(node_map.GetNode("Height")): self.camera.Height = self.parameters['height'] if genicam.IsWritable(node_map.GetNode("OffsetX")): self.camera.CenterX = True # self.camera.OffsetX = 256 if genicam.IsWritable(node_map.GetNode("OffsetY")): self.camera.CenterY = True # self.camera.OffsetY = 176 if genicam.IsWritable(node_map.GetNode("PixelFormat")): self.camera.PixelFormat = "Mono8" if genicam.IsWritable(node_map.GetNode("AcquisitionFrameRateEnable")): self.camera.AcquisitionFrameRateEnable = True if genicam.IsWritable(node_map.GetNode("AcquisitionFrameRate")): self.camera.AcquisitionFrameRate = self.parameters['fps'] if genicam.IsWritable(node_map.GetNode("ExposureTime")): self.camera.ExposureTime = self.parameters['exposure_time']
def change_ROI(camera, dimensions, offsets): """ Change the camera ROI to capture only those pixels from the sensor. Arguments: camera : active camera object dimensions : tuple of (width, height) of ROI in pixels offsets : tuple of (x-offset, y-offset) from the left top corner in pixels returns: modified camera object """ try: # Maximize the Image AOI. camera.Width = dimensions[0] camera.Height = dimensions[1] if genicam.IsWritable(camera.OffsetX): camera.OffsetX = offsets[0] if genicam.IsWritable(camera.OffsetY): camera.OffsetY = offsets[1] except genicam.GenericException as e: raise genicam.RuntimeException("Could not apply configuration. GenICam::GenericException \ caught in OnOpened method msg=%s" % e.what()) return return camera
def set_default_params(self): """ MaxNumBuffer: 8 """ print("\n\t\t~~~~ Setting Default Parameters ~~~~") # Amplification of camera signal try: self.cam.GainAuto.SetValue("Off") self.cam.Gain = 2.28869 print("\nGain: {} dB".format(self.cam.Gain())) except Exception as e: print("\ncam.Gain FAILED!") print(e) raise # Exposure time try: self.cam.ExposureAuto.SetValue("Off") self.cam.ExposureTime = 60000 # us print("\nExposure Time: {} us".format(self.cam.ExposureTime())) except Exception as e: print("\ncam.ExposureTime FAILED!") print(e) raise # ROI Size and position try: if genicam.IsWritable(self.cam.Width): self.cam.Width = self.cam.Width.Max # self.cam.Width.SetValue(1248) if genicam.IsWritable(self.cam.Height): self.cam.Height = self.cam.Height.Max # self.cam.Height.SetValue(750) if genicam.IsWritable(self.cam.OffsetX): self.cam.OffsetX = self.cam.OffsetX.Min # self.cam.OffsetX.SetValue(544) if genicam.IsWritable(self.cam.OffsetY): self.cam.OffsetY = self.cam.OffsetY.Min # self.cam.OffsetY.SetValue(800) print("\nImage ROI") print("\tOffsetX: {} px".format(self.cam.OffsetX.GetValue())) print("\tOffsetY: {} px".format(self.cam.OffsetY.GetValue())) print("\tWidth: {} px".format(self.cam.Width.GetValue())) print("\tHeight: {} px".format(self.cam.Height.GetValue())) except Exception as e: print("\nSetting ROI FAILED!") print(e) raise
def OnOpened(self, camera): try: # Maximize the Image AOI. if genicam.IsWritable(camera.OffsetX): camera.OffsetX = camera.OffsetX.Min if genicam.IsWritable(camera.OffsetY): camera.OffsetY = camera.OffsetY.Min camera.Width = camera.Width.Max camera.Height = camera.Height.Max # Set the pixel data format. camera.PixelFormat = "Mono8" except genicam.GenericException as e: raise genicam.RuntimeException( "Could not apply configuration. GenICam::GenericException \ caught in OnOpened method msg=%s" % e.what())
def set_offsety(self, offsety): """ Set Camera ROI Y Axis Offset """ try: if genicam.IsWritable(self.cam.OffsetY): self.cam.OffsetY = offsety except Exception as e: print("\ncam.OffsetY FAILED!") print(e) raise
def set_offsetx(self, offsetx): """ Set Camera ROI X Axis Offset """ try: if genicam.IsWritable(self.cam.OffsetX): self.cam.OffsetX = offsetx except Exception as e: print("\ncam.OffsetX FAILED!") print(e) raise
def set_height(self, height): """ Set Camera ROI Height """ try: if genicam.IsWritable(self.cam.Height): self.cam.Height = height except Exception as e: print("\ncam.Height FAILED!") print(e) raise
def set_width(self, width): """ Set Camera ROI Width """ try: if genicam.IsWritable(self.cam.Width): self.cam.Width = width except Exception as e: print("\ncam.Width FAILED!") print(e) raise
def test_grab_chunk_image(self): # Only look for usb cameras info = pylon.DeviceInfo() info.SetDeviceClass("BaslerUsb") # Create an instant camera object with the first found camera device that matches the specified device class. camera = pylon.InstantCamera( pylon.TlFactory.GetInstance().CreateFirstDevice(info)) # Open the camera. camera.Open() camera.StaticChunkNodeMapPoolSize = camera.MaxNumBuffer.GetValue() if genicam.IsWritable(camera.ChunkModeActive): camera.ChunkModeActive = True else: self.fail() # Enable time stamp chunks. camera.ChunkSelector = "Timestamp" camera.ChunkEnable = True # Enable CRC checksum chunks. camera.ChunkSelector = "PayloadCRC16" camera.ChunkEnable = True camera.StartGrabbingMax(self.countOfImagesToGrab) while camera.IsGrabbing(): # Wait for an image and then retrieve it. A timeout of 5000 ms is used. # RetrieveResult calls the image event handler's OnImageGrabbed method. grabResult = camera.RetrieveResult( 5000, pylon.TimeoutHandling_ThrowException) # Check to see if a buffer containing chunk data has been received. if pylon.PayloadType_ChunkData != grabResult.PayloadType: self.fail() # 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 grabResult.HasCRC() and grabResult.CheckCRC() == False: self.fail() if not genicam.IsReadable(grabResult.ChunkTimestamp): self.fail() camera.ChunkModeActive = False
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 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
# Register an image event handler that accesses the chunk data. camera.RegisterImageEventHandler(SampleImageEventHandler(), pylon.RegistrationMode_Append, pylon.Cleanup_Delete) # 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.RuntimeException("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"