basler / pypylon

The official python wrapper for the pylon Camera Software Suite
http://www.baslerweb.com
BSD 3-Clause "New" or "Revised" License
567 stars 207 forks source link

Possible bug with ExposureTime.Min changing #46

Closed campanelli-resonon closed 6 years ago

campanelli-resonon commented 6 years ago

I'm using pypylon 1.3.1 with Anaconda Python 3.6.6 and Pylon 5.0.12.11830 64-bit on Windows 10.

I am seeing an issue when I query a USB Ace acA1920-155um camera for its minimum exposure time. I first configure an imager object that holds the camera object, which is created using:

self.camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())

Then I store the minimum exposure time using (camera opening and closing not shown):

self.exposure_time_min = self.camera.ExposureTime.Min

Later, I rely on this value for a lower bound in a search routine, but when setting the exposure time to the stored minimum value (using self.camera.ExposureTime.SetValue) the camera raises an exception that self.exposure_time_min is too small. Here is the exception:

Value 20.000000 must be greater than or equal 21.000000. : OutOfRangeException thrown in node 'ExposureTime' while calling 'ExposureTime.SetValue()' (file 'FloatT.h', line 85)

This exception is only thrown the first time the program is run after plugging the camera in to the computer. It is not thrown subsequently, until it is plugged out and back in again. (Specifically, the initial minimum value is only returned as 20 us the first time, and 21 us subsequently, so my program only breaks on the first run after plugging in the camera.) This makes me think it is a bug somewhere in the Basler API, but perhaps the minimum exposure value is not truly fixed and changes depending on the circumstances?

thiesmoeller commented 6 years ago

As a general note: Most features of a machine vision camera depend on each other. Manipulating one value could affect the limits of another.

In your program, I would modify the search routine to always fetch the min/max values from the device. The underlying genicam model is caching stable values to optimize performance. [ The model automatically invalidates the cache if a value changes as a side effect of setting a feature ] Due to the caches queries to features are cheap. A camera.ExposureTime.Min doesn't result in a call to the camera device itself, but is answered from the object model.

campanelli-resonon commented 6 years ago

@thiesmoeller Indeed, I think this issue is caused by improper ordering of my camera configuration. If I read and store these values after setting the windowing, etc., then I get a consistent value later. That said, I will consider a further refactor that will rely on the camera to provide these values in all cases. Thanks!