aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Myers <sam.myers@inventia.life>2017-03-04 11:27:25 +1100
committerSam Myers <sam.myers@inventia.life>2017-03-04 11:27:25 +1100
commite97a71a576b36a6a7cda4d488056ddb316738df5 (patch)
tree0da3f11bb32b48ff0fc22181b6ecfaff6bcb76da
parent3c6c75e07c513595a639e4af9aed23d1e8f2b4ff (diff)
downloadpymba-e97a71a576b36a6a7cda4d488056ddb316738df5.tar.gz
pymba-e97a71a576b36a6a7cda4d488056ddb316738df5.zip
py3 changes
-rw-r--r--.gitignore4
-rw-r--r--pymba/__init__.py5
-rw-r--r--pymba/tests/opencv_example.py9
-rw-r--r--pymba/tests/opencv_liveview_example.py11
-rw-r--r--pymba/tests/opencv_liveview_example_color.py2
-rw-r--r--pymba/tests/test_cameras.py13
-rw-r--r--pymba/tests/test_installation.py2
-rw-r--r--pymba/tests/test_interfaces.py11
-rw-r--r--pymba/tests/test_systemfeature.py8
-rw-r--r--pymba/vimba.py16
-rw-r--r--pymba/vimbacamera.py15
-rw-r--r--pymba/vimbadll.py33
-rw-r--r--pymba/vimbaexception.py1
-rw-r--r--pymba/vimbafeature.py20
-rw-r--r--pymba/vimbaframe.py9
-rw-r--r--pymba/vimbainterface.py9
-rw-r--r--pymba/vimbaobject.py17
-rw-r--r--pymba/vimbasystem.py5
18 files changed, 98 insertions, 92 deletions
diff --git a/.gitignore b/.gitignore
index d2d6f36..692ad13 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,7 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject
+
+# PyCharm
+.idea/
+.cache/
diff --git a/pymba/__init__.py b/pymba/__init__.py
index 96a931e..c6c69cd 100644
--- a/pymba/__init__.py
+++ b/pymba/__init__.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
-from vimba import Vimba
-from vimbaexception import VimbaException
+from __future__ import absolute_import
+from .vimba import Vimba
+from .vimbaexception import VimbaException
diff --git a/pymba/tests/opencv_example.py b/pymba/tests/opencv_example.py
index e89cccc..238e8b4 100644
--- a/pymba/tests/opencv_example.py
+++ b/pymba/tests/opencv_example.py
@@ -1,3 +1,4 @@
+from __future__ import absolute_import, print_function, division
from pymba import *
import numpy as np
import cv2
@@ -16,7 +17,7 @@ with Vimba() as vimba:
time.sleep(0.2)
cameraIds = vimba.getCameraIds()
for cameraId in cameraIds:
- print 'Camera ID:', cameraId
+ print('Camera ID:', cameraId)
# get and open a camera
camera0 = vimba.getCamera(cameraIds[0])
@@ -25,7 +26,7 @@ with Vimba() as vimba:
# list camera features
cameraFeatureNames = camera0.getFeatureNames()
for name in cameraFeatureNames:
- print 'Camera feature:', name
+ print('Camera feature:', name)
# read info of a camera feature
#featureInfo = camera0.getFeatureInfo('AcquisitionMode')
@@ -33,7 +34,7 @@ with Vimba() as vimba:
# print field, '--', getattr(featInfo, field)
# get the value of a feature
- print camera0.AcquisitionMode
+ print(camera0.AcquisitionMode)
# set the value of a feature
camera0.AcquisitionMode = 'SingleFrame'
@@ -64,7 +65,7 @@ with Vimba() as vimba:
1))
rgb = cv2.cvtColor(moreUsefulImgData, cv2.COLOR_BAYER_RG2RGB)
cv2.imwrite('foo{}.png'.format(count), rgb)
- print "image {} saved".format(count)
+ print("image {} saved".format(count))
count += 1
camera0.endCapture()
# clean up after capture
diff --git a/pymba/tests/opencv_liveview_example.py b/pymba/tests/opencv_liveview_example.py
index e6fc89f..78b6b67 100644
--- a/pymba/tests/opencv_liveview_example.py
+++ b/pymba/tests/opencv_liveview_example.py
@@ -5,6 +5,7 @@ Created on Mon Jul 07 14:59:03 2014
@author: derricw
"""
+from __future__ import absolute_import, print_function, division
from pymba import *
import numpy as np
import cv2
@@ -21,15 +22,15 @@ with Vimba() as vimba:
camera_ids = vimba.getCameraIds()
for cam_id in camera_ids:
- print "Camera found: ", cam_id
+ print("Camera found: ", cam_id)
c0 = vimba.getCamera(camera_ids[0])
c0.openCamera()
try:
#gigE camera
- print c0.GevSCPSPacketSize
- print c0.StreamBytesPerSecond
+ print(c0.GevSCPSPacketSize)
+ print(c0.StreamBytesPerSecond)
c0.StreamBytesPerSecond = 100000000
except:
#not a gigE camera
@@ -67,8 +68,8 @@ with Vimba() as vimba:
k = cv2.waitKey(1)
if k == 0x1b:
cv2.destroyAllWindows()
- print "Frames displayed: %i"%framecount
- print "Frames dropped: %s"%droppedframes
+ print("Frames displayed: %i"%framecount)
+ print("Frames dropped: %s"%droppedframes)
break
diff --git a/pymba/tests/opencv_liveview_example_color.py b/pymba/tests/opencv_liveview_example_color.py
index 5b531fe..fd7a819 100644
--- a/pymba/tests/opencv_liveview_example_color.py
+++ b/pymba/tests/opencv_liveview_example_color.py
@@ -13,7 +13,7 @@ OpenCV is expecting color images to be in BGR8Packed by default. It can work
just uses its default behavior.
"""
-
+from __future__ import absolute_import, print_function, division
from pymba import *
import numpy as np
import cv2
diff --git a/pymba/tests/test_cameras.py b/pymba/tests/test_cameras.py
index 3699e93..a5a4dd9 100644
--- a/pymba/tests/test_cameras.py
+++ b/pymba/tests/test_cameras.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-
+from __future__ import absolute_import, print_function, division
from pymba import *
import time
@@ -14,9 +14,10 @@ def test_cameras():
if system.GeVTLIsPresent:
system.runFeatureCommand("GeVDiscoveryAllOnce")
time.sleep(0.2)
+
cameraIds = vimba.getCameraIds()
for cameraId in cameraIds:
- print 'Camera ID:', cameraId
+ print('Camera ID:', cameraId)
# get and open a camera
camera0 = vimba.getCamera(cameraIds[0])
@@ -25,10 +26,10 @@ def test_cameras():
# list camera features
cameraFeatureNames = camera0.getFeatureNames()
for name in cameraFeatureNames:
- print 'Camera feature:', name
+ print('Camera feature:', name)
# get the value of a feature
- print camera0.AcquisitionMode
+ print(camera0.AcquisitionMode)
# set the value of a feature
camera0.AcquisitionMode = 'SingleFrame'
@@ -65,3 +66,7 @@ def test_cameras():
# close camera
camera0.closeCamera()
+
+
+if __name__ == '__main__':
+ test_cameras() \ No newline at end of file
diff --git a/pymba/tests/test_installation.py b/pymba/tests/test_installation.py
index 775c529..06af7d6 100644
--- a/pymba/tests/test_installation.py
+++ b/pymba/tests/test_installation.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-
+from __future__ import absolute_import, print_function, division
from pymba import Vimba
diff --git a/pymba/tests/test_interfaces.py b/pymba/tests/test_interfaces.py
index 4014690..270d42c 100644
--- a/pymba/tests/test_interfaces.py
+++ b/pymba/tests/test_interfaces.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-
+from __future__ import absolute_import, print_function, division
from pymba import *
import time
@@ -10,7 +10,7 @@ def test_interfaces():
# get list of available interfaces
interfaceIds = vimba.getInterfaceIds()
for interfaceId in interfaceIds:
- print 'Interface ID:', interfaceId
+ print('Interface ID:', interfaceId)
# get interface object and open it
interface0 = vimba.getInterface(interfaceIds[0])
@@ -19,7 +19,10 @@ def test_interfaces():
# list interface features
interfaceFeatureNames = interface0.getFeatureNames()
for name in interfaceFeatureNames:
- print 'Interface feature:', name
+ print('Interface feature:', name)
# close interface
- interface0.closeInterface() \ No newline at end of file
+ interface0.closeInterface()
+
+if __name__ == '__main__':
+ test_interfaces() \ No newline at end of file
diff --git a/pymba/tests/test_systemfeature.py b/pymba/tests/test_systemfeature.py
index e5168d5..abb4da7 100644
--- a/pymba/tests/test_systemfeature.py
+++ b/pymba/tests/test_systemfeature.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-
+from __future__ import absolute_import, print_function, division
from pymba import *
@@ -10,9 +10,11 @@ def test_systemfeature():
# list system features
for featureName in system.getFeatureNames():
- print 'System feature:', featureName
+ print('System feature:', featureName)
fInfo = system.getFeatureInfo(featureName)
for field in fInfo.getFieldNames():
- print "\t", featureName, ":", field, getattr(fInfo, field)
+ print("\t", featureName, ":", field, getattr(fInfo, field))
+if __name__ == '__main__':
+ test_systemfeature() \ No newline at end of file
diff --git a/pymba/vimba.py b/pymba/vimba.py
index 2f78ea5..d2bf9dd 100644
--- a/pymba/vimba.py
+++ b/pymba/vimba.py
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
-import vimbastructure as structs
-from vimbadll import VimbaDLL
-from vimbaexception import VimbaException
-from vimbasystem import VimbaSystem
-from vimbacamera import VimbaCamera
-from vimbainterface import VimbaInterface
+from __future__ import absolute_import
+import pymba.vimbastructure as structs
+from .vimbadll import VimbaDLL
+from .vimbaexception import VimbaException
+from .vimbasystem import VimbaSystem
+from .vimbacamera import VimbaCamera
+from .vimbainterface import VimbaInterface
from ctypes import *
@@ -73,7 +74,6 @@ class Vimba(object):
byref(numFound),
sizeof(dummyInterfaceInfo))
if errorCode != 0:
- print errorCode
raise VimbaException(errorCode)
numInterfaces = numFound.value
@@ -149,7 +149,7 @@ class Vimba(object):
:returns: list -- camera IDs for available cameras.
"""
- return list(camInfo.cameraIdString for camInfo in self._getCameraInfos())
+ return list(camInfo.cameraIdString.decode() for camInfo in self._getCameraInfos())
def getInterfaceInfo(self, interfaceId):
"""
diff --git a/pymba/vimbacamera.py b/pymba/vimbacamera.py
index e08a69e..74821cd 100644
--- a/pymba/vimbacamera.py
+++ b/pymba/vimbacamera.py
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
-import vimbastructure as structs
-from vimbaobject import VimbaObject
-from vimbaexception import VimbaException
-from vimbaframe import VimbaFrame
-from vimbadll import VimbaDLL
+from __future__ import absolute_import
+import pymba.vimbastructure as structs
+from .vimbaobject import VimbaObject
+from .vimbaexception import VimbaException
+from .vimbaframe import VimbaFrame
+from .vimbadll import VimbaDLL
from ctypes import *
# camera features are automatically readable as object attributes.
@@ -18,7 +19,7 @@ class VimbaCamera(VimbaObject):
@property
def cameraIdString(self):
- return self._cameraIdString
+ return self._cameraIdString.decode()
# own handle is inherited as self._handle
def __init__(self, cameraIdString):
@@ -27,7 +28,7 @@ class VimbaCamera(VimbaObject):
super(VimbaCamera, self).__init__()
# set ID
- self._cameraIdString = cameraIdString
+ self._cameraIdString = cameraIdString.encode()
# set own info
self._info = self._getInfo()
diff --git a/pymba/vimbadll.py b/pymba/vimbadll.py
index c446bd6..7ba6e14 100644
--- a/pymba/vimbadll.py
+++ b/pymba/vimbadll.py
@@ -1,11 +1,14 @@
# -*- coding: utf-8 -*-
-import vimbastructure as structs
-from vimbaexception import VimbaException
+from __future__ import absolute_import
+
from sys import platform as sys_plat
import platform
import os
from ctypes import *
+import pymba.vimbastructure as structs
+from .vimbaexception import VimbaException
+
if sys_plat == "win32":
def find_win_dll(arch):
@@ -25,15 +28,13 @@ if sys_plat == "win32":
raise IOError("VimbaC.dll not found.")
return dlls[-1]
- from ctypes.util import find_msvcrt
- _cruntime = cdll.LoadLibrary(find_msvcrt())
if '64' in platform.architecture()[0]:
vimbaC_path = find_win_dll(64)
else:
vimbaC_path = find_win_dll(32)
dll_loader = windll
else:
- _cruntime = CDLL("libc.so.6")
+
dll_loader = cdll
assert os.environ.get(
"GENICAM_GENTL64_PATH"), "you need your GENICAM_GENTL64_PATH environment set. Make sure you have Vimba installed, and you have loaded the /etc/profile.d/ scripts"
@@ -41,9 +42,6 @@ else:
[1:-3])
vimbaC_path = "/" + vimba_dir + "/VimbaC/DynamicLib/x86_64bit/libVimbaC.so"
-with open(vimbaC_path) as thefile:
- pass # NJO i think this is kind of like an os.exists ?
-
# Callback Function Type
if sys_plat == "win32":
@@ -429,29 +427,16 @@ class VimbaC_MemoryBlock(object):
neatly with C memory allocations.
"""
- # C runtime DLL
- _crtDLL = _cruntime
-
@property
def block(self):
- return self._block
+ return c_void_p(addressof(self._block))
def __init__(self, blockSize):
-
- # assign memory block
- malloc = self._crtDLL.malloc
- malloc.argtypes = (c_size_t,)
- malloc.restype = c_void_p
- self._block = malloc(blockSize) # todo check for NULL on failure
+ self._block = create_string_buffer(blockSize)
# this seems to be None if too much memory is requested
if self._block is None:
raise VimbaException(-51)
def __del__(self):
-
- # free memory block
- free = self._crtDLL.free
- free.argtypes = (c_void_p,)
- free.restype = None
- free(self._block)
+ del self._block
diff --git a/pymba/vimbaexception.py b/pymba/vimbaexception.py
index 87e4a70..6269543 100644
--- a/pymba/vimbaexception.py
+++ b/pymba/vimbaexception.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
-import exceptions
class VimbaException(Exception):
diff --git a/pymba/vimbafeature.py b/pymba/vimbafeature.py
index 540044d..3f68989 100644
--- a/pymba/vimbafeature.py
+++ b/pymba/vimbafeature.py
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
-import vimbastructure as structs
-from vimbaexception import VimbaException
-from vimbadll import VimbaDLL
+from __future__ import absolute_import
+import pymba.vimbastructure as structs
+from .vimbaexception import VimbaException
+from .vimbadll import VimbaDLL
from ctypes import *
# class may extend a generic Vimba entity class one day...
@@ -15,7 +16,7 @@ class VimbaFeature(object):
@property
def name(self):
- return self._name
+ return self._name.decode()
@property
def handle(self):
@@ -37,7 +38,7 @@ class VimbaFeature(object):
def __init__(self, name, handle):
# set name and handle
- self._name = name
+ self._name = name.encode()
self._handle = handle
# set own info
@@ -178,7 +179,7 @@ class VimbaFeature(object):
if errorCode != 0:
raise VimbaException(errorCode)
- return valueToGet.value
+ return valueToGet.value.decode()
def _setEnumFeature(self, valueToSet):
"""
@@ -189,7 +190,7 @@ class VimbaFeature(object):
errorCode = VimbaDLL.featureEnumSet(self._handle,
self._name,
- valueToSet)
+ valueToSet.encode())
if errorCode != 0:
raise VimbaException(errorCode)
@@ -212,8 +213,7 @@ class VimbaFeature(object):
byref(sizeFilled))
if errorCode != 0:
raise VimbaException(errorCode)
-
- return valueToGet.value
+ return valueToGet.value.decode()
def _setStringFeature(self, valueToSet):
"""
@@ -224,7 +224,7 @@ class VimbaFeature(object):
errorCode = VimbaDLL.featureStringSet(self._handle,
self._name,
- valueToSet)
+ valueToSet.encode())
if errorCode != 0:
raise VimbaException(errorCode)
diff --git a/pymba/vimbaframe.py b/pymba/vimbaframe.py
index 6efaec9..5495d5c 100644
--- a/pymba/vimbaframe.py
+++ b/pymba/vimbaframe.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-import vimbastructure as structs
-from vimbaexception import VimbaException
-from vimbadll import VimbaDLL
-from vimbadll import VimbaC_MemoryBlock
+from __future__ import absolute_import
+import pymba.vimbastructure as structs
+from .vimbaexception import VimbaException
+from .vimbadll import VimbaDLL
+from .vimbadll import VimbaC_MemoryBlock
from ctypes import *
import warnings
try:
diff --git a/pymba/vimbainterface.py b/pymba/vimbainterface.py
index 63963ba..ab2e050 100644
--- a/pymba/vimbainterface.py
+++ b/pymba/vimbainterface.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-import vimbastructure as structs
-from vimbaobject import VimbaObject
-from vimbaexception import VimbaException
-from vimbadll import VimbaDLL
+from __future__ import absolute_import
+import pymba.vimbastructure as structs
+from .vimbaobject import VimbaObject
+from .vimbaexception import VimbaException
+from .vimbadll import VimbaDLL
from ctypes import *
# interface features are automatically readable as object attributes.
diff --git a/pymba/vimbaobject.py b/pymba/vimbaobject.py
index 9f57c62..d3ed861 100644
--- a/pymba/vimbaobject.py
+++ b/pymba/vimbaobject.py
@@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
-import vimbastructure as structs
-from vimbaexception import VimbaException
-from vimbafeature import VimbaFeature
-from vimbadll import VimbaDLL
+from __future__ import absolute_import
+import pymba.vimbastructure as structs
+from .vimbaexception import VimbaException
+from .vimbafeature import VimbaFeature
+from .vimbadll import VimbaDLL
from ctypes import *
@@ -106,7 +107,7 @@ class VimbaObject(object):
:returns: list -- feature names for available features.
"""
- return list(featInfo.name for featInfo in self._getFeatureInfos())
+ return list(featInfo.name.decode() for featInfo in self._getFeatureInfos())
def getFeatureInfo(self, featureName):
"""
@@ -119,7 +120,7 @@ class VimbaObject(object):
# don't do this live as we already have this info
# return info object, if it exists
for featInfo in self._getFeatureInfos():
- if featInfo.name == featureName:
+ if featInfo.name.decode() == featureName:
return featInfo
# otherwise raise error
raise VimbaException(-53)
@@ -136,7 +137,7 @@ class VimbaObject(object):
:returns: tuple -- range as (feature min value, feature max value).
"""
# can't cache this, need to look it up live
- return VimbaFeature(featureName, self._handle).range
+ return VimbaFeature(featureName.encode(), self._handle).range
def runFeatureCommand(self, featureName):
"""
@@ -146,7 +147,7 @@ class VimbaObject(object):
"""
# run a command
errorCode = VimbaDLL.featureCommandRun(self._handle,
- featureName)
+ featureName.encode())
if errorCode != 0:
raise VimbaException(errorCode)
diff --git a/pymba/vimbasystem.py b/pymba/vimbasystem.py
index 94cc49e..d1f9603 100644
--- a/pymba/vimbasystem.py
+++ b/pymba/vimbasystem.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
-from vimbaobject import VimbaObject
-from ctypes import *
+from __future__ import absolute_import
+from .vimbaobject import VimbaObject
+from ctypes import c_void_p
# system features are automatically readable as attributes.