morefigs / pymba

Python wrapper for Allied Vision's Vimba C API
MIT License
105 stars 84 forks source link

Force open a camera after crash #132

Closed rk-exxec closed 4 years ago

rk-exxec commented 4 years ago

Hey, is there a way to force open a camera ( i.e. close all other connections)? I am working on a program, and it crashes a lot. It leaves the vimba object and the camera in the open state which causes issues when I try to start my program again.

I tried self.cam.run_feature_command('DeviceReset') but this requires an open connection. I tried closing the camera before opening it, doesn't work.

I'm using vimba 4.0

The crashes themselves seem to be caused by self.cam.disarm() during a continuous acquisition. My callback looks like this:

def frame_handler(self, frame: Frame, delay: Optional[int] = 1) -> None:
    try:
        img = frame.buffer_data_numpy()
    except:
        pass
    self.change_pixmap_signal.emit(img)

If I omit the last line, my program doesn't crash anymore. So if someone has an idea about that, please let me know.

rk-exxec commented 4 years ago

I started using the official library and figured out a way to "force close" a camera. This should also work here. You need to get the "AcquisitionStatus" feature value after selecting "AcquisitionActive" in the "AcquisitionStatusSelector" feature. Then if its true, run the "AcquisitionStop" command feature.

The crash is also gone, but I don't know exactly why.

rk-exxec commented 4 years ago

BTW here is how:

def _init_camera(self):
    with self._vimba:
        cams = self._vimba.get_all_cameras()
        self._cam = cams[0]
        with self._cam:
            self._cam.AcquisitionStatusSelector.set('AcquisitionActive')
            if self._cam.AcquisitionStatus.get():
                self._cam.AcquisitionStop.run()
                # fetch broken frame
                self._cam.get_frame()

could be ported to this library, I'm sure.