jordens / pyflycapture2

python bindings for the flycapture v2 api (libflycapture-2c)
37 stars 31 forks source link

Get Camera form serial number no attribute error #16

Closed DPastl closed 8 years ago

DPastl commented 8 years ago

Hello,

First of all, thanks a ton for writing this, it's going to save me a ton of effort writing my own API wrapper.

The problem I'm having is that I'd like to connect to a specific device according to it's serial number. Now I can just do a look through all the devices found, but it looks like there's a function in the flycapture.pyx file called "get_camera_from_serial_number" that would do it for me. However when I try to call it I get an error saying that:

AttributeError: 'flycapture2.Context' object has no attribute 'get_camera_from_serial_number'

After I attempt to run:

self.camera = fc2.Context() self.camera.connect(*self.camera.get_camera_from_serial_number(serial_number))

Is there any way to get around this?

Thanks!

jordens commented 8 years ago

Are you certain that you are using a reecent version of pyflycapture2?

import flycapture2 as fc2
serial_number = 1234567
ctx = fc2.Context()
ctx.connect(*ctx.get_camera_from_serial_number(serial_number))
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    ctx.connect(*ctx.get_camera_from_serial_number(serial_number))
  File "src/flycapture2.pyx", line 95, in flycapture2.Context.get_camera_from_serial_number (src/flycapture2.c:3018)
    raise_error(r)
  File "src/flycapture2.pyx", line 40, in flycapture2.raise_error (src/flycapture2.c:2138)
    raise ApiError(e, fc2ErrorToDescription(e))
flycapture2.ApiError: (19, b'Bus Master Failure.')
DPastl commented 8 years ago

I did a git pull yesterday. I tried cleaning up the directory and rebuilding but that didn't help.

Here's the log:

`running install running bdist_egg running egg_info creating pyflycapture2.egg-info writing requirements to pyflycapture2.egg-info/requires.txt writing pyflycapture2.egg-info/PKG-INFO writing top-level names to pyflycapture2.egg-info/top_level.txt writing dependency_links to pyflycapture2.egg-info/dependency_links.txt writing manifest file 'pyflycapture2.egg-info/SOURCES.txt' reading manifest file 'pyflycapture2.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'pyflycapture2.egg-info/SOURCES.txt' installing library code to build/bdist.linux-x86_64/egg running install_lib running build_ext skipping 'src/flycapture2.c' Cython extension (up-to-date) building 'flycapture2' extension creating build creating build/temp.linux-x86_64-2.7 creating build/temp.linux-x86_64-2.7/src x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/flycapture/C -IC:/Program Files/Point Grey Research/FlyCapture2/include/C -I/usr/lib/python2.7/dist-packages/numpy/core/include -I/usr/include/python2.7 -c src/flycapture2.c -o build/temp.linux-x86_64-2.7/src/flycapture2.o In file included from src/flycapture2.c:272:0: /usr/include/flycapture/C/FlyCapture2_C.h:395:3: warning: function declaration isn’t a prototype [-Wstrict-prototypes] fc2ForceAllIPAddressesAutomatically(); ^ /usr/include/flycapture/C/FlyCapture2_C.h:1515:3: warning: function declaration isn’t a prototype [-Wstrict-prototypes] ResetStats(); ^ In file included from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1777:0, from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/ndarrayobject.h:18, from /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/arrayobject.h:4, from src/flycapture2.c:276: /usr/lib/python2.7/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

warning "Using deprecated NumPy API, disable it by " \

^ src/flycapture2.c: In function ‘pyx_pf_11flycapture2_5Image_4__array’: src/flycapture2.c:6923:36: warning: passing argument 1 of ‘(PyObject * (_)(PyTypeObject , PyArray_Descr , int, npy_intp , npy_intp , void , int, PyObject ))_(PyArray_API + 752u)’ from incompatible pointer type [-Wincompatible-pointer-types] pyx_t_1 = PyArray_NewFromDescr(((PyObject *)__pyx_ptype_5numpy_ndarray), pyx_v_dtype, 2, __pyxv ^ src/flycapture2.c:6923:36: note: expected ‘PyTypeObject * {aka struct _typeobject }’ but argument is of type ‘PyObject * {aka struct _object }’ creating build/lib.linux-x86_64-2.7 x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/flycapture2.o -LC:/Program Files/Point Grey Research/FlyCapture2/lib64/C -lflycapture-c -o build/lib.linux-x86_64-2.7/flycapture2.so creating build/bdist.linux-x86_64 creating build/bdist.linux-x86_64/egg copying build/lib.linux-x86_64-2.7/flycapture2.so -> build/bdist.linux-x86_64/egg creating stub loader for flycapture2.so byte-compiling build/bdist.linux-x86_64/egg/flycapture2.py to flycapture2.pyc creating build/bdist.linux-x86_64/egg/EGG-INFO copying pyflycapture2.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO copying pyflycapture2.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying pyflycapture2.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying pyflycapture2.egg-info/requires.txt -> build/bdist.linux-x86_64/egg/EGG-INFO copying pyflycapture2.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt zip_safe flag not set; analyzing archive contents... creating dist creating 'dist/pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it removing 'build/bdist.linux-x86_64/egg' (and everything under it) Processing pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg Removing /usr/local/lib/python2.7/dist-packages/pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg Copying pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg to /usr/local/lib/python2.7/dist-packages pyflycapture2 0.1+dev is already the active version in easy-install.pth

Installed /usr/local/lib/python2.7/dist-packages/pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg Processing dependencies for pyflycapture2==0.1+dev Searching for numpy==1.11.0 Best match: numpy 1.11.0 numpy 1.11.0 is already the active version in easy-install.pth

Using /usr/lib/python2.7/dist-packages Finished processing dependencies for pyflycapture2==0.1+dev `

jordens commented 8 years ago

Could you coonfirm that the module you are importing and using is the one you are compiling and installing?

DPastl commented 8 years ago

It's the only python flycapture software on my computer, but just to be sure I checked the path from the import:

import os import inspect inspect.getfile(flycapture2) Traceback (most recent call last): File "", line 1, in NameError: name 'flycapture2' is not defined import flycapture2 inspect.getfile(flycapture2) '/home/pastl/.python-eggs/pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg-tmp/flycapture2.so'

Looking at the file system, this file was last modified on sept 16, which makes sense since I tried to recompile to see if that would fix the problem on Friday.

jordens commented 8 years ago

Thanks. Could you either try the script I pasted above or supply the actual code you are running that generates the error?

DPastl commented 8 years ago

Here are the results of running that script you posted above:

import flycapture2 as fc2

serial_number = 1234567 ctx = fc2.Context() ctx.connect(*ctx.get_camera_from_serial_number(serial_number)) Traceback (most recent call last): File "", line 1, in AttributeError: 'flycapture2.Context' object has no attribute 'get_camera_from_serial_number'

jordens commented 8 years ago

Pretty sure that your python tree is messed up. I would guess you have a pyflycapture2 in /home/pastl/.python-eggs/pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg-tmp/ and one in /usr/local/lib/python2.7/dist-packages/pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg (at least).

DPastl commented 8 years ago

Hmm... The local one is simply the unzipped version of the one in /lib/, which python does each time I import the module. I tried deleting it but the problem persisted. As far as I can tell there's nothing wrong with the paths, python is expanding the egg from /lib/ to /home/* as it should, then loading the expanded files.

I'm guessing it has to do with the build process, I'll have to look into it more when I can afford the time.

jordens commented 8 years ago

Could be. I am not an expert on that egg caching. To exclude this as an issue, could you try to uninstall/remove/delete the installed package until import flycapture2 stops working and then install it again? And then please:

>>> import flycapture2 as fc2
>>> dir(fc2.Context)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'connect', 'disconnect', 'fire_software_trigger', 'get_camera_from_index', 'get_camera_from_serial_number', 'get_camera_info', 'get_configuration', 'get_format7_configuration', 'get_format7_info', 'get_num_of_cameras', 'get_num_of_devices', 'get_property', 'get_property_info', 'get_strobe_mode', 'get_trigger_mode', 'get_video_mode_and_frame_rate', 'get_video_mode_and_frame_rate_info', 'retrieve_buffer', 'set_configuration', 'set_format7_configuration', 'set_property', 'set_strobe_mode', 'set_trigger_mode', 'set_user_buffers', 'set_video_mode_and_frame_rate', 'start_capture', 'stop_capture']
>>> assert "get_camera_from_serial_number" in dir(fc2.Context)
>>>
DPastl commented 8 years ago

Cleaned and rebuilt the package and still had the issue, but on a whim I decided to do a git clone of your repo, instead of just downloading the zip as I had originally done. This fixed the problem:

>>> import flycapture2 as fc2
/usr/local/lib/python2.7/dist-packages/pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg/flycapture2.py:3: UserWarning: Module flycapture2 was already imported from /usr/local/lib/python2.7/dist-packages/pyflycapture2-0.1+dev-py2.7-linux-x86_64.egg/flycapture2.pyc, but /home/pastl/Applications/pyflycapture2 is being added to sys.path
>>> dir(fc2.Context)
['__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'connect', 'disconnect', 'fire_software_trigger', 'get_camera_from_index', 'get_camera_from_serial_number', 'get_camera_info', 'get_configuration', 'get_format7_configuration', 'get_format7_info', 'get_num_of_cameras', 'get_num_of_devices', 'get_property', 'get_property_info', 'get_strobe_mode', 'get_trigger_mode', 'get_video_mode_and_frame_rate', 'get_video_mode_and_frame_rate_info', 'retrieve_buffer', 'set_configuration', 'set_format7_configuration', 'set_property', 'set_strobe_mode', 'set_trigger_mode', 'set_user_buffers', 'set_video_mode_and_frame_rate', 'start_capture', 'stop_capture']
>>> assert "get_camera_from_serial_number" in dir(fc2.Context)

Seems there's an issue with downloading the zip file for some reason... I have no idea why that would make a difference.

I'll make sure to do a git clone from now on. Thanks!