1111import time
1212
1313import gi
14- gi .require_version ('Aravis' , '0.6' )
14+
15+ gi .require_version ("Aravis" , "0.6" )
1516from gi .repository import Aravis
1617import cv2
1718
1819from dlclivegui .camera import Camera
1920
2021
2122class AravisCam (Camera ):
22-
23-
2423 @staticmethod
2524 def arg_restrictions ():
2625
2726 Aravis .update_device_list ()
2827 n_cams = Aravis .get_n_devices ()
2928 ids = [Aravis .get_device_id (i ) for i in range (n_cams )]
30- return {'id' : ids }
31-
32-
33- def __init__ (self , id = '' , resolution = [720 ,540 ], exposure = .005 , gain = 0 , rotate = 0 , crop = None , fps = 100 , display = True , display_resize = 1.0 ):
34-
35- super ().__init__ (id , resolution = resolution , exposure = exposure , gain = gain , rotate = rotate , crop = crop , fps = fps , use_tk_display = display , display_resize = display_resize )
36-
29+ return {"id" : ids }
30+
31+ def __init__ (
32+ self ,
33+ id = "" ,
34+ resolution = [720 , 540 ],
35+ exposure = 0.005 ,
36+ gain = 0 ,
37+ rotate = 0 ,
38+ crop = None ,
39+ fps = 100 ,
40+ display = True ,
41+ display_resize = 1.0 ,
42+ ):
43+
44+ super ().__init__ (
45+ id ,
46+ resolution = resolution ,
47+ exposure = exposure ,
48+ gain = gain ,
49+ rotate = rotate ,
50+ crop = crop ,
51+ fps = fps ,
52+ use_tk_display = display ,
53+ display_resize = display_resize ,
54+ )
3755
3856 def set_capture_device (self ):
3957
@@ -49,31 +67,27 @@ def set_capture_device(self):
4967
5068 return True
5169
52-
5370 def no_auto (self ):
5471
5572 self .cam .set_exposure_time_auto (0 )
5673 self .cam .set_gain_auto (0 )
5774
58-
5975 def set_exposure (self , val ):
6076
6177 val = 1 if val > 1 else val
6278 val = 0 if val < 0 else val
63- self .cam .set_exposure_time (val * 1e6 )
64-
79+ self .cam .set_exposure_time (val * 1e6 )
6580
6681 def set_crop (self , crop ):
6782
6883 if crop :
6984 left = crop [0 ]
70- width = crop [1 ]- left
85+ width = crop [1 ] - left
7186 top = crop [3 ]
72- height = top - crop [2 ]
87+ height = top - crop [2 ]
7388 self .cam .set_region (left , top , width , height )
7489 self .im_size = (width , height )
7590
76-
7791 def get_image_on_time (self ):
7892
7993 buffer = None
@@ -85,12 +99,11 @@ def get_image_on_time(self):
8599
86100 return frame , time .time ()
87101
88-
89102 def _convert_image_to_numpy (self , buffer ):
90- ''' from https://github.com/SintefManufacturing/python-aravis '''
103+ """ from https://github.com/SintefManufacturing/python-aravis """
91104
92105 pixel_format = buffer .get_image_pixel_format ()
93- bits_per_pixel = pixel_format >> 16 & 0xff
106+ bits_per_pixel = pixel_format >> 16 & 0xFF
94107
95108 if bits_per_pixel == 8 :
96109 INTP = ctypes .POINTER (ctypes .c_uint8 )
@@ -100,15 +113,16 @@ def _convert_image_to_numpy(self, buffer):
100113 addr = buffer .get_data ()
101114 ptr = ctypes .cast (addr , INTP )
102115
103- frame = np .ctypeslib .as_array (ptr , (buffer .get_image_height (), buffer .get_image_width ()))
116+ frame = np .ctypeslib .as_array (
117+ ptr , (buffer .get_image_height (), buffer .get_image_width ())
118+ )
104119 frame = frame .copy ()
105120
106121 if frame .ndim < 3 :
107122 frame = cv2 .cvtColor (frame , cv2 .COLOR_GRAY2RGB )
108123
109124 return frame
110125
111-
112126 def close_capture_device ():
113127
114- self .cam .stop_acquisition ()
128+ self .cam .stop_acquisition ()
0 commit comments