@@ -44,10 +44,6 @@ def __init__(self, serial_number):
4444 self .camera = PyCapture2 .Camera ()
4545 self .camera .connect (bus .getCameraFromSerialNumber (serial_number ))
4646
47- config = self .camera .getConfiguration ()
48- config .grabTimeout = 1000 # in ms
49- config .highPerformanceRetrieveBuffer = True
50- self .camera .setConfiguration (config )
5147 # set which values of properties to return
5248 self .get_props = ['present' ,'absControl' ,'absValue' ,
5349 'onOff' ,'autoManualMode' ,
@@ -60,6 +56,12 @@ def __init__(self, serial_number):
6056 self .pixel_formats = IntEnum ('pixel_formats' ,fmts )
6157
6258 self ._abort_acquisition = False
59+
60+ # set standard device configuration
61+ config = self .camera .getConfiguration ()
62+ config .grabTimeout = 1000 # in ms
63+ config .highPerformanceRetrieveBuffer = True
64+ self .camera .setConfiguration (config )
6365
6466 # check if GigE camera. If so, ensure max packet size is used
6567 cam_info = self .camera .getCameraInfo ()
@@ -84,6 +86,19 @@ def __init__(self, serial_number):
8486 # close second handle to camera
8587 gige_camera .disconnect ()
8688
89+ # ensure camera is in Format7,Mode 0 custom image mode
90+ fmt7_info , supported = self .camera .getFormat7Info (0 )
91+ if supported :
92+ # to ensure Format7, must set custom image settings
93+ # defaults to full sensor size and 'MONO8' pixel format
94+ fmt7_default = PyCapture2 .Format7ImageSettings (0 ,0 ,0 ,fmt7_info .maxWidth ,fmt7_info .maxHeight ,self .pixel_formats ['MONO8' ])
95+ self ._send_format7_config (fmt7_default )
96+
97+ else :
98+ msg = """Camera does not support Format7, Mode 0 custom image
99+ configuration. This driver is therefore not compatible, as written."""
100+ raise RuntimeError (dedent (msg ))
101+
87102 def set_attributes (self , attr_dict ):
88103 """Sets all attribues in attr_dict.
89104 FlyCapture does not control all settings through same interface,
@@ -145,12 +160,8 @@ def set_image_mode(self,image_settings):
145160 for k ,v in image_dict .items ():
146161 setattr (image_mode ,k ,v )
147162
148- try :
149- fmt7PktInfo , valid = self .camera .validateFormat7Settings (image_mode )
150- if valid :
151- self .camera .setFormat7ConfigurationPacket (fmt7PktInfo .recommendedBytesPerPacket , image_mode )
152- except PyCapture2 .Fc2error as e :
153- raise RuntimeError ('Error configuring image settings' ) from e
163+ self ._send_format7_config (image_mode )
164+
154165 else :
155166 msg = """Camera does not support Format7, Mode 0 custom image
156167 configuration. This driver is therefore not compatible, as written."""
@@ -301,6 +312,15 @@ def _decode_image_data(self,img):
301312 uint8 data to desired format in _decode_image_data() method."""
302313 raise ValueError (dedent (msg ))
303314 return image .copy ()
315+
316+ def _send_format7_config (self ,image_config ):
317+ """Validates and sends the Format7 configuration packet."""
318+ try :
319+ fmt7PktInfo , valid = self .camera .validateFormat7Settings (image_config )
320+ if valid :
321+ self .camera .setFormat7ConfigurationPacket (fmt7PktInfo .recommendedBytesPerPacket , image_config )
322+ except PyCapture2 .Fc2error as e :
323+ raise RuntimeError ('Error configuring image settings' ) from e
304324
305325 def stop_acquisition (self ):
306326 self .camera .stopCapture ()
0 commit comments