def get_device_from(factory=None, **kwargs): di = pylon.DeviceInfo() for key, value in kwargs.items(): if key == "IpAddress": value = socket.gethostbyname(value) getattr(di, "Set" + key)(value) return get_device_from_info(di, factory)
def __init__(self, serialNumber): """ Initializes a Camera with the given serial number """ self.cam = None self.serial = serialNumber device_info = py.DeviceInfo() device_info.SetSerialNumber(serialNumber) self.cam = py.InstantCamera( py.TlFactory.GetInstance().CreateDevice(device_info)) self.lock = Lock()
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 __init__(self, ip_address='169.254.203.55'): info = pylon.DeviceInfo() info.SetPropertyValue('IpAddress', ip_address) self.camera = pylon.InstantCamera( pylon.TlFactory.GetInstance().CreateFirstDevice(info)) #self.camera.ExposureTimeAbs = 500 # Grabing Continusely (video) with minimal delay self.camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly) self.converter = pylon.ImageFormatConverter() # self.camera.PixelFormat = 'BGR8Packed' print(self.camera.PixelFormat()) # converting to opencv bgr format self.converter.OutputPixelFormat = pylon.PixelType_BGR8packed self.converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned print('Connected')
async def _connect_internal(self): """Connect to a camera uid is serial number """ info = pylon.DeviceInfo() info.SetSerialNumber(self.uid) cam = pylon.InstantCamera( pylon.TlFactory.GetInstance().CreateFirstDevice(info)) cam.Open() # reverse Y so that image in ds9 displays correctly cam.ReverseY = True cam.PixelFormat = "Mono12" cam.Gain = cam.Gain.Min cam.Width = cam.Width.Max cam.Height = cam.Height.Max cam.BinningHorizontal = 1 cam.BinningVertical = 1 cam.BinningVerticalMode = "Sum" cam.BinningHorizontalMode = "Sum" self.device = cam
# Load Yolo net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg") classes = [] with open("coco.names", "r") as f: classes = [line.strip() for line in f.readlines()] layer_names = net.getLayerNames() output_layers = [layer_names[i[0] - 1] for i in net.getUnconnectedOutLayers()] colors = np.random.uniform(0, 255, size=(len(classes), 3)) # conecting to the first available camera #camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice()) # connecting to the camera with specific IP ip_address = '192.168.3.110' info = pylon.DeviceInfo() info.SetPropertyValue('IpAddress', ip_address) camera = pylon.InstantCamera( pylon.TlFactory.GetInstance().CreateFirstDevice(info)) # Set Inter-Packet Delay in the Transport Layer to control bandwidth of camera. If not set it properly, It will fail to grab the image. camera.Open() camera.GevSCPD.SetValue(9000) # Set Inter-Packet Delay (In tick) # Grabing Continusely (video) camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly) converter = pylon.ImageFormatConverter() # converting to opencv bgr format converter.OutputPixelFormat = pylon.PixelType_BGR8packed converter.OutputBitAlignment = pylon.OutputBitAlignment_MsbAligned
def get_class_and_filter(): device_class = "BaslerCamEmu" di = pylon.DeviceInfo() di.SetDeviceClass(device_class) return device_class, [di]
while True: if cameraArray.IsGrabbing(): for camera in cameraArray: camera.ExecuteSoftwareTrigger() time.sleep(1 / float(triggerRate)) try: # number of images to grab from each camera numberOfImages = 10 # framerate to trigger at frameRate = 10 # for demo purposes, we will only look for certain types of cameras filters = list() filter1 = pylon.DeviceInfo() filter1.SetDeviceClass("BaslerUsb") filters.append(filter1) # detect and enumerate devices into a device info list tlFactory = pylon.TlFactory.GetInstance() devices = tlFactory.EnumerateDevices(filters) # We will use however many cameras are found numberOfCameras = len(devices) # The InstantCameraArray is generic (interface agnostic) # It encapsulates the physical camera and driver into one convinient object cameras = pylon.InstantCameraArray(numberOfCameras) # Attach each camera in the array to a physical device
def test_grab_events(self): print("test_grab_event") self.assertTrue(True) # Create an example event handler. In the present case, we use one single camera handler for handling multiple camera events. # The handler prints a message for each received event. handler1 = SampleCameraEventHandler() # Create another more generic event handler printing out information about the node for which an event callback # is fired. handler2 = CameraEventPrinter() # Only look for cameras supported by Camera_t info = pylon.DeviceInfo() # info.SetDeviceClass( ## fetch deviceclass from environment ##); info.SetDeviceClass("BaslerUsb") # Create an instant camera object with the first found camera device matching the specified device class. camera = pylon.InstantCamera( pylon.TlFactory.GetInstance().CreateFirstDevice(info)) # Register the standard configuration event handler for enabling software triggering. # The software trigger configuration handler replaces the default configuration # as all currently registered configuration handlers are removed by setting the registration mode to RegistrationMode_ReplaceAll. camera.RegisterConfiguration(pylon.SoftwareTriggerConfiguration(), pylon.RegistrationMode_ReplaceAll, pylon.Cleanup_Delete) # For demonstration purposes only, add sample configuration event handlers to print out information # about camera use and image grabbing. # camera.RegisterConfiguration(ConfigurationEventPrinter(), pylon.RegistrationMode_Append, # pylon.Cleanup_Delete) # Camera use. # For demonstration purposes only, register another image event handler. camera.RegisterImageEventHandler(SampleImageEventHandler(), pylon.RegistrationMode_Append, pylon.Cleanup_Delete) # Camera event processing must be activated first, the default is off. camera.GrabCameraEvents = True # Register an event handler for the Exposure End event. For each event type, there is a "data" node # representing the event. The actual data that is carried by the event is held by child nodes of the # data node. In the case of the Exposure End event, the child nodes are EventExposureEndFrameID and EventExposureEndTimestamp. # The CSampleCameraEventHandler demonstrates how to access the child nodes within # a callback that is fired for the parent data node. # The user-provided ID eMyExposureEndEvent can be used to distinguish between multiple events (not shown). camera.RegisterCameraEventHandler(handler1, "EventExposureEndData", eMyExposureEndEvent, pylon.RegistrationMode_ReplaceAll, pylon.Cleanup_None) # The handler is registered for both, the EventExposureEndFrameID and the EventExposureEndTimestamp # node. These nodes represent the data carried by the Exposure End event. # For each Exposure End event received, the handler will be called twice, once for the frame ID, and # once for the time stamp. camera.RegisterCameraEventHandler(handler2, "EventExposureEndFrameID", eMyExposureEndEvent, pylon.RegistrationMode_Append, pylon.Cleanup_None) camera.RegisterCameraEventHandler(handler2, "EventExposureEndTimestamp", eMyExposureEndEvent, pylon.RegistrationMode_Append, pylon.Cleanup_None) # Open the camera for setting parameters. camera.Open() camera.ExposureTime.Value = camera.ExposureTime.Min # Check if the device supports events. if not genicam.IsAvailable(camera.EventSelector): raise genicam.RuntimeException( "The device doesn't support events.") # Enable sending of Exposure End events. # Select the event to receive. camera.EventSelector = "ExposureEnd" # Enable it. camera.EventNotification = "On" # Start the grabbing of c_countOfImagesToGrab images. camera.StartGrabbingMax(self.countOfImagesToGrab) # Camera.StopGrabbing() is called automatically by the RetrieveResult() method # when c_countOfImagesToGrab images have been retrieved. while camera.IsGrabbing(): # Execute the software trigger. Wait up to 1000 ms for the camera to be ready for trigger. if camera.WaitForFrameTriggerReady( 100, pylon.TimeoutHandling_ThrowException): camera.ExecuteSoftwareTrigger() # Retrieve grab results and notify the camera event and image event handlers. grabResult = camera.RetrieveResult(100) # Nothing to do here with the grab result, the grab results are handled by the registered event handler. # Disable sending Exposure End events. camera.EventSelector = "ExposureEnd" camera.EventNotification = "Off" camera.Close()