morefigs / pymba

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

python 3.5 #29

Closed hstarmans closed 5 years ago

hstarmans commented 8 years ago

Dear all,

I am using a modified version of Pymba for Python 3.5. There are several challenges if Pymba is ported to Python 3.5.1, Windows 7, 64 bit major issue:

 from ctypes.util import find_msvcrt
 find_mscvct()

This code, located in vimbadll, does not work in Python 3.5.1, see python bug 26727 For some reason, the find_mscvcrt does not work and returns "none". I know fixed it with:

_cruntime = cdll.LoadLibrary('msvcr100.dll')

This works but according to [python bug 26727] my expectation 'msvcr100.dll' is incorrect. minor issues:

print "something" should be print("something")

byte strings --> in python 3 you need to use encode and decode. New style imports i.e.;

from . import vimbastructure as structs
from .vimbaobject import VimbaObject
mabl commented 8 years ago

Hi @hstarmans, please have a look at #22 & #19, which address these problems. Feel free to test the branch and correct the reaming errors there.

draustin commented 8 years ago

Hi all,

Thank you @mabl for providing this.

I have tested #22 on Python 3.5.1, Win 64, Vimba 1.4, Guppy PRO F201B. All tests and demos worked except test_interfaces, which crashes on the final line interface0.closeInterface().

Since I'm new to github I'll be specific about what I did: I ran git fetch origin pull/22/head:python3 and reinstalled pymba.

hstarmans commented 8 years ago

Dear all, My apologies for my late response. Thank you @mabl, your solution was better than the temporary fix I used. @draustin , thank you for your help with Git. I have tested it with Python 3.5.1 and win32. I had to resolve one merge conflict in pympa.py. I still need to run the tests and will update this post with test result once I have done this.

hstarmans commented 8 years ago

Dear all, I have tried the code from @mabl. The code partly works on Windows 7 64 bit with vimba 2.0. I have to start the vimba viewer, connect to the camera, click play, click stop and close the viewer. If I do not execute this procedure the code does not work and I get a timeout, i.e. error code -12. I use an ethernet camera GB2450 gigE.

from pymba import Vimba
from time import sleep
vimba=Vimba()
vimba.startup()
vimsys=vimba.getSystem()
if vimsys.GeVTLIsPresent:
    vimsys.runFeatureCommand("GeVDiscoveryAllOnce")
    sleep(0.2)
camera0=vimba.getCamera(vimba.getCameraIds()[0])
camera0.openCamera()
camera0.AcquisitionMode='SingleFrame'
camera0.ExposureTimeAbs=6000  # duration in microseconds
# create new frames for the camera
frame0 = camera0.getFrame()    
# announce frame
frame0.announceFrame()
# capture a camera image
camera0.startCapture()
frame0.queueFrameCapture()
camera0.runFeatureCommand('AcquisitionStart')
sleep(0.2) # was suggested in other comment, but don't think it is needed
camera0.runFeatureCommand('AcquisitionStop')
result=frame0.waitFrameCapture()
if result!=0:
    print("First; open vimba viewer,connect to camera, click play, click stop and closer viewer otherwise this code does not work")
mabl commented 8 years ago

Does this code work for you with stock master branch? I find it difficult to believe that device discovery would differ with the python 3 branch. However, I do not have a network camera, so no idea if your code is fully correct...

hstarmans commented 8 years ago

@mabl, you are correct; the code also does not work with the stock master branch. The problem does not seem to be related to the modifications in the Python 3 branch. I have run the tests provided with xstools with both Python 2 and python 3. The opencv-example.py only works if I have started and closed the vimba viewer before executing the test.

morefigs commented 7 years ago

Try again, code has changed slightly.

hstarmans commented 7 years ago

Thanks for the changes. I do, however, no longer have access to the camera. I was using the code for a camera in a 3D printer from my previous employer. I have mailed a former colleague; but can't test it myself.