55Licensed under GNU Lesser General Public License v3.0
66"""
77
8- import pypylon as pylon
8+ #import pypylon as pylon
9+ from pypylon import pylon
910from imutils import rotate_bound
1011import time
1112
1213from dlclivegui .camera import Camera , CameraError
14+ TIMEOUT = 100
1315
16+ def get_devices ():
17+ tlFactory = pylon .TlFactory .GetInstance ()
18+ devices = tlFactory .EnumerateDevices ()
19+ return devices
1420
1521class BaslerCam (Camera ):
1622 @staticmethod
1723 def arg_restrictions ():
1824 """ Returns a dictionary of arguments restrictions for DLCLiveGUI
1925 """
20-
21- tlFactory = pylon .TlFactory .GetInstance ()
22- devices = tlFactory .EnumerateDevices ()
23-
24- return {"device" : devices , "display" : [True , False ]}
26+ devices = get_devices ()
27+ device_ids = list (range (len (devices )))
28+ return {"device" : device_ids , "display" : [True , False ]}
2529
2630 def __init__ (
2731 self ,
28- device = "" ,
32+ device = 0 ,
2933 resolution = [640 , 480 ],
30- exposure = 0 ,
34+ exposure = 15000 ,
3135 rotate = 0 ,
3236 crop = None ,
37+ gain = 0.0 ,
3338 fps = 30 ,
3439 display = True ,
3540 display_resize = 1.0 ,
@@ -41,6 +46,7 @@ def __init__(
4146 exposure = exposure ,
4247 rotate = rotate ,
4348 crop = crop ,
49+ gain = gain ,
4450 fps = fps ,
4551 use_tk_display = display ,
4652 display_resize = display_resize ,
@@ -50,12 +56,14 @@ def __init__(
5056
5157 def set_capture_device (self ):
5258
59+ devices = get_devices ()
5360 self .cam = pylon .InstantCamera (
54- pylon .TlFactory .GetInstance ().CreateDevice (self .id ))
61+ pylon .TlFactory .GetInstance ().CreateDevice (devices [self .id ])
62+ )
5563 self .cam .Open ()
5664
5765 self .cam .Gain .SetValue (self .gain )
58- self .cam .Exposure .SetValue (self .exposure )
66+ self .cam .ExposureTime .SetValue (self .exposure )
5967 self .cam .Width .SetValue (self .im_size [0 ])
6068 self .cam .Height .SetValue (self .im_size [1 ])
6169
@@ -67,9 +75,8 @@ def set_capture_device(self):
6775 return True
6876
6977 def get_image (self ):
70-
7178 grabResult = self .cam .RetrieveResult (
72- 1 , pylon .TimeoutHandling_ThrowException )
79+ TIMEOUT , pylon .TimeoutHandling_ThrowException )
7380
7481 frame = None
7582
0 commit comments