aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Sun <jsun@sightmachine.com>2014-04-02 17:08:07 -0700
committerJohn Sun <jsun@sightmachine.com>2014-04-02 17:08:07 -0700
commitc40423dd47d6ba56469ae1faf306d95d6be5cd5c (patch)
tree3333906a098b9c22a3e89ec53473a0acec7d0c43
parent01e24424971ffa9faa5dabf2e6724cea997a2afb (diff)
downloadpymba-c40423dd47d6ba56469ae1faf306d95d6be5cd5c.tar.gz
pymba-c40423dd47d6ba56469ae1faf306d95d6be5cd5c.zip
Add some tests
test_systemfeature.py is broken because I think this is invalid API.
-rw-r--r--pyvimba/tests/__init__.py0
-rw-r--r--pyvimba/tests/opencv_example.py2
-rw-r--r--pyvimba/tests/test_cameras.py70
-rw-r--r--pyvimba/tests/test_installation.py8
-rw-r--r--pyvimba/tests/test_interfaces.py29
-rw-r--r--pyvimba/tests/test_systemfeature.py19
6 files changed, 127 insertions, 1 deletions
diff --git a/pyvimba/tests/__init__.py b/pyvimba/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/pyvimba/tests/__init__.py
diff --git a/pyvimba/tests/opencv_example.py b/pyvimba/tests/opencv_example.py
index 36b5108..a1d7269 100644
--- a/pyvimba/tests/opencv_example.py
+++ b/pyvimba/tests/opencv_example.py
@@ -1,4 +1,4 @@
-from vimba import *
+from pyvimba.vimba import *
import numpy as np
import cv2
import time
diff --git a/pyvimba/tests/test_cameras.py b/pyvimba/tests/test_cameras.py
new file mode 100644
index 0000000..b9f42d4
--- /dev/null
+++ b/pyvimba/tests/test_cameras.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+
+from pyvimba.vimba import *
+import time
+
+def test_cameras():
+ # start Vimba
+ vimba = Vimba()
+ vimba.startup()
+
+ # get system object
+ system = vimba.getSystem()
+
+ # list available cameras (after enabling discovery for GigE cameras)
+ if system.GeVTLIsPresent:
+ system.runFeatureCommand("GeVDiscoveryAllOnce")
+ time.sleep(0.2)
+ cameraIds = vimba.getCameraIds()
+ for cameraId in cameraIds:
+ print 'Camera ID:', cameraId
+
+ # get and open a camera
+ camera0 = vimba.getCamera(cameraIds[0])
+ camera0.openCamera()
+
+ # list camera features
+ cameraFeatureNames = camera0.getFeatureNames()
+ for name in cameraFeatureNames:
+ print 'Camera feature:', name
+
+ # get the value of a feature
+ print camera0.AcquisitionMode
+
+ # set the value of a feature
+ camera0.AcquisitionMode = 'SingleFrame'
+
+ # create new frames for the camera
+ frame0 = camera0.getFrame() # creates a frame
+ frame1 = camera0.getFrame() # creates a second frame
+
+ # announce frame
+ frame0.announceFrame()
+
+ # capture a camera image
+ camera0.startCapture()
+ frame0.queueFrameCapture()
+ camera0.runFeatureCommand('AcquisitionStart')
+ camera0.runFeatureCommand('AcquisitionStop')
+ frame0.waitFrameCapture()
+
+ # get image data...
+ imgData = frame0.getBufferByteData()
+
+ # ...or use NumPy for fast image display (for use with OpenCV, etc)
+ import numpy as np
+ moreUsefulImgData = np.ndarray(buffer = frame0.getBufferByteData(),
+ dtype = np.uint8,
+ shape = (frame0.height,
+ frame0.width,
+ 1))
+
+ # clean up after capture
+ camera0.endCapture()
+ camera0.revokeAllFrames()
+
+ # close camera
+ camera0.closeCamera()
+
+ # shutdown Vimba
+ vimba.shutdown()
diff --git a/pyvimba/tests/test_installation.py b/pyvimba/tests/test_installation.py
new file mode 100644
index 0000000..060f453
--- /dev/null
+++ b/pyvimba/tests/test_installation.py
@@ -0,0 +1,8 @@
+#!/usr/bin/python
+
+from pyvimba.vimba import *
+
+def test_installation():
+ vimba = Vimba()
+ version = vimba.getVersion()
+ assert version == '1.2.0'
diff --git a/pyvimba/tests/test_interfaces.py b/pyvimba/tests/test_interfaces.py
new file mode 100644
index 0000000..2620289
--- /dev/null
+++ b/pyvimba/tests/test_interfaces.py
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+
+from pyvimba.vimba import *
+import time
+
+def test_interfaces():
+ # start Vimba
+ vimba = Vimba()
+ vimba.startup()
+
+ # get list of available interfaces
+ interfaceIds = vimba.getInterfaceIds()
+ for interfaceId in interfaceIds:
+ print 'Interface ID:', interfaceId
+
+ # get interface object and open it
+ interface0 = vimba.getInterface(interfaceIds[0])
+ interface0.openInterface()
+
+ # list interface features
+ interfaceFeatureNames = interface0.getFeatureNames()
+ for name in interfaceFeatureNames:
+ print 'Interface feature:', name
+
+ # close interface
+ interface0.closeInterface()
+
+ # shutdown Vimba
+ vimba.shutdown()
diff --git a/pyvimba/tests/test_systemfeature.py b/pyvimba/tests/test_systemfeature.py
new file mode 100644
index 0000000..2fb5760
--- /dev/null
+++ b/pyvimba/tests/test_systemfeature.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+from pyvimba.vimba import *
+
+def test_systemfeature():
+ # get system object
+ vimba = Vimba()
+ system = vimba.getSystem()
+
+ # get system object
+ system = vimba.getSystem()
+
+ # list system features
+ for featureName in system.getFeatureNames():
+ print 'System feature:', featureName
+
+ # shutdown Vimba
+ vimba.shutdown()
+