morefigs / pymba

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

pymba crashes with Vimba 3.0 sdk #97

Open sudheerExperiments opened 5 years ago

sudheerExperiments commented 5 years ago

Hello,

I recently updated my Vimba SDK . Pymba was working fine with 2.9 but it is crashing with 3.0.

The crash occurs in the below two lines.

camera.disarm()
camera.close()

Any help would be appreciated. Thanks!

morefigs commented 5 years ago

Does this example work for you? https://github.com/morefigs/pymba/blob/master/examples/camera/opencv_acquire_image.py

sudheerExperiments commented 5 years ago

It works but when I press ctrl +c to terminate my program, the window just hangs and crashes. This problem wasn't there when I used vimba 2.9.

I am attaching a screenshot from my program after I press 'Ctrl +c'. pymba detects the keypress event but just waits indefinitely without returning to the command prompt. This problem wasn't there with Vimba 2.9 or earlier release.

I am guessing this has to do with some Windows DLL files.

I could roll back to the previous version but they don't have that SDK online anymore.

Annotation 2019-07-10 125901

Popup of the error

Annotation 2019-07-10 131400

morefigs commented 5 years ago

I generally wouldn't expect a program to end nicely upon CTRL+C unless perhaps you're catching the command within Python. Could you post a minimal example that can recreate the bug?

sudheerExperiments commented 5 years ago

Hello @morefigs,

Here's a sample code of what I am working. I have three cameras in my setup. What I am basically doing in this example is, I am running the three cams in the infinete loop and displaying the grabbed images.

from pymba import Vimba
from pymba import VimbaException
import cv2
import sys

def init_cameras():
        # vimba object
        vimba = Vimba()
        # Start vimba system
        vimba.startup()
        vmFactory = vimba.camera_ids()
        # Get connected cameras
        cams = [vimba.camera(id) for id in vmFactory]
        if len(cams) == 0:
            raise OSError("No camera present.")
        for idx, device in enumerate(vmFactory):
            print("Device {} ID: {}".format(idx, device))
        # Open cameras and print information
        for idx, cam in enumerate(cams):
            try:
                cam.open()
                cam.arm('SingleFrame')
            except VimbaException as e:
                if e.error_code == VimbaException.ERR_TIMEOUT:
                    print(e)
                    cam.disarm()
                    cam.arm('SingleFrame')
                elif e.error_code == VimbaException.ERR_DEVICE_NOT_OPENED:
                    print(e)
                    cam.open()
                    cam.arm('SingleFrame')
        return cams

def main():
    PIXEL_FORMATS_CONVERSIONS = { 'BayerRG8': cv2.COLOR_BAYER_RG2RGB}
    cams = init_cameras()
    flag = True
    while flag:
        try:
            for idx, cam in enumerate(cams):
                frame = cam.acquire_frame()
                img = frame.buffer_data_numpy()
                # convert color space if desired
                img = cv2.cvtColor(img, PIXEL_FORMATS_CONVERSIONS[frame.pixel_format])
                cv2.imshow("Cam {} - {}".format(idx, ["cam{}". format(idx)]), img)
                c = cv2.waitKey(5)
                if c == ord('q'):
                    flag = False
        except KeyboardInterrupt:
            sys.exit(1)
    for cam in cams:
        cam.disarm()
        cam.close()
    cv2.destroyAllWindows()

if __name__ == '__main__':
    main()

Sample output:

Device 0 ID: DEV_000F31008103 Device 1 ID: DEV_000F31008105 Device 2 ID: DEV_000F31008104

cmd prompt just hangs when I hit 'ctrl + c' or 'q'.

You should be able to replicate the issue with this example. Let me know if you have any questions.

sudheerExperiments commented 5 years ago

@morefigs Any update on this issue?

morefigs commented 5 years ago

Sorry, haven't had time or enough cameras to debug this and likely won't soon. I can't see any obvious reason this wouldn't work, however. Did you figure it out?

SunnyAVT commented 5 years ago

@sudheerExperiments, I copy and run your code in my test PC(win10 Pro 64bit, Python3.6 and Vimba SDK 3.0, I hit 'q', it has not any problem, not crash. The test result is as attached picture. Maybe you can give me more info for how to re-produce the issue. Pymba_image_crash_test BTW, the previous Vimba SDK is V2.1.3, not V2.9.

kthumma2 commented 1 year ago

Hello , Can anyone help me out how to set up the path for Vimba 6.0 on my windows ? I Have installed Vimba SDK but I am unable to set path for the bin. i am trying to interact this Vimba with my python code i am unable to do it. Any suggestions?