aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/opencv_example.py76
-rw-r--r--tests/opencv_liveview_example.py79
-rw-r--r--tests/opencv_liveview_example_color.py89
-rw-r--r--tests/test_cameras.py72
-rw-r--r--tests/test_enumfeature.py25
-rw-r--r--tests/test_installation.py9
-rw-r--r--tests/test_interfaces.py28
-rw-r--r--tests/test_systemfeature.py20
9 files changed, 398 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/opencv_example.py b/tests/opencv_example.py
new file mode 100644
index 0000000..238e8b4
--- /dev/null
+++ b/tests/opencv_example.py
@@ -0,0 +1,76 @@
+from __future__ import absolute_import, print_function, division
+from pymba import *
+import numpy as np
+import cv2
+import time
+
+#very crude example, assumes your camera is PixelMode = BAYERRG8
+
+# start Vimba
+with Vimba() as vimba:
+ # 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)
+
+ # read info of a camera feature
+ #featureInfo = camera0.getFeatureInfo('AcquisitionMode')
+ #for field in featInfo.getFieldNames():
+ # print field, '--', getattr(featInfo, field)
+
+ # 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
+ count = 0
+ while count < 10:
+ camera0.startCapture()
+ frame0.queueFrameCapture()
+ camera0.runFeatureCommand('AcquisitionStart')
+ camera0.runFeatureCommand('AcquisitionStop')
+ frame0.waitFrameCapture()
+
+ # get image data...
+ imgData = frame0.getBufferByteData()
+
+ moreUsefulImgData = np.ndarray(buffer = frame0.getBufferByteData(),
+ dtype = np.uint8,
+ shape = (frame0.height,
+ frame0.width,
+ 1))
+ rgb = cv2.cvtColor(moreUsefulImgData, cv2.COLOR_BAYER_RG2RGB)
+ cv2.imwrite('foo{}.png'.format(count), rgb)
+ print("image {} saved".format(count))
+ count += 1
+ camera0.endCapture()
+ # clean up after capture
+ camera0.revokeAllFrames()
+
+ # close camera
+ camera0.closeCamera()
+
diff --git a/tests/opencv_liveview_example.py b/tests/opencv_liveview_example.py
new file mode 100644
index 0000000..78b6b67
--- /dev/null
+++ b/tests/opencv_liveview_example.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+"""
+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
+import time
+
+cv2.namedWindow("test")
+
+with Vimba() as vimba:
+ system = vimba.getSystem()
+
+ system.runFeatureCommand("GeVDiscoveryAllOnce")
+ time.sleep(0.2)
+
+ camera_ids = vimba.getCameraIds()
+
+ for cam_id in camera_ids:
+ print("Camera found: ", cam_id)
+
+ c0 = vimba.getCamera(camera_ids[0])
+ c0.openCamera()
+
+ try:
+ #gigE camera
+ print(c0.GevSCPSPacketSize)
+ print(c0.StreamBytesPerSecond)
+ c0.StreamBytesPerSecond = 100000000
+ except:
+ #not a gigE camera
+ pass
+
+ #set pixel format
+ c0.PixelFormat="Mono8"
+ #c0.ExposureTimeAbs=60000
+
+ frame = c0.getFrame()
+ frame.announceFrame()
+
+ c0.startCapture()
+
+ framecount = 0
+ droppedframes = []
+
+ while 1:
+ try:
+ frame.queueFrameCapture()
+ success = True
+ except:
+ droppedframes.append(framecount)
+ success = False
+ c0.runFeatureCommand("AcquisitionStart")
+ c0.runFeatureCommand("AcquisitionStop")
+ frame.waitFrameCapture(1000)
+ frame_data = frame.getBufferByteData()
+ if success:
+ img = np.ndarray(buffer=frame_data,
+ dtype=np.uint8,
+ shape=(frame.height,frame.width,1))
+ cv2.imshow("test",img)
+ framecount+=1
+ k = cv2.waitKey(1)
+ if k == 0x1b:
+ cv2.destroyAllWindows()
+ print("Frames displayed: %i"%framecount)
+ print("Frames dropped: %s"%droppedframes)
+ break
+
+
+ c0.endCapture()
+ c0.revokeAllFrames()
+
+ c0.closeCamera()
diff --git a/tests/opencv_liveview_example_color.py b/tests/opencv_liveview_example_color.py
new file mode 100644
index 0000000..fd7a819
--- /dev/null
+++ b/tests/opencv_liveview_example_color.py
@@ -0,0 +1,89 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Mon Jul 07 14:59:03 2014
+
+@author: derricw
+
+Same as the other liveview example, but displays in color.
+
+Obviously you want to use a camera that has a color mode like BGR8Packed
+
+OpenCV is expecting color images to be in BGR8Packed by default. It can work
+ with other formats as well as convert one to the other, but this example
+ just uses its default behavior.
+
+"""
+from __future__ import absolute_import, print_function, division
+from pymba import *
+import numpy as np
+import cv2
+import time
+import sys
+
+cv2.namedWindow("test")
+
+with Vimba() as vimba:
+ system = vimba.getSystem()
+
+ system.runFeatureCommand("GeVDiscoveryAllOnce")
+ time.sleep(0.2)
+
+ camera_ids = vimba.getCameraIds()
+
+ for cam_id in camera_ids:
+ print("Camera found: ", cam_id)
+
+ c0 = vimba.getCamera(camera_ids[0])
+ c0.openCamera()
+
+ try:
+ #gigE camera
+ print("Packet size:", c0.GevSCPSPacketSize)
+ c0.StreamBytesPerSecond = 100000000
+ print("BPS:", c0.StreamBytesPerSecond)
+ except:
+ #not a gigE camera
+ pass
+
+ #set pixel format
+ c0.PixelFormat = "BGR8Packed" # OPENCV DEFAULT
+ time.sleep(0.2)
+
+ frame = c0.getFrame()
+ frame.announceFrame()
+
+ c0.startCapture()
+
+ framecount = 0
+ droppedframes = []
+
+ while 1:
+ try:
+ frame.queueFrameCapture()
+ success = True
+ except:
+ droppedframes.append(framecount)
+ success = False
+ c0.runFeatureCommand("AcquisitionStart")
+ c0.runFeatureCommand("AcquisitionStop")
+ frame.waitFrameCapture(1000)
+ frame_data = frame.getBufferByteData()
+ if success:
+ img = np.ndarray(buffer=frame_data,
+ dtype=np.uint8,
+ shape=(frame.height, frame.width, frame.pixel_bytes))
+ cv2.imshow("test", img)
+ framecount += 1
+ k = cv2.waitKey(1)
+ if k == 0x1b:
+ cv2.destroyAllWindows()
+ print("Frames displayed: %i" % framecount)
+ print("Frames dropped: %s" % droppedframes)
+ break
+
+
+ c0.endCapture()
+ c0.revokeAllFrames()
+
+ c0.closeCamera()
+
diff --git a/tests/test_cameras.py b/tests/test_cameras.py
new file mode 100644
index 0000000..a5a4dd9
--- /dev/null
+++ b/tests/test_cameras.py
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+from __future__ import absolute_import, print_function, division
+from pymba import *
+import time
+
+
+def test_cameras():
+ # start Vimba
+ with Vimba() as vimba:
+ # 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()
+
+
+if __name__ == '__main__':
+ test_cameras() \ No newline at end of file
diff --git a/tests/test_enumfeature.py b/tests/test_enumfeature.py
new file mode 100644
index 0000000..7f9dd4c
--- /dev/null
+++ b/tests/test_enumfeature.py
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+from __future__ import absolute_import, print_function, division
+from pymba import *
+
+
+def test_enumfeature():
+ # get system object
+ with Vimba() as vimba:
+ system = vimba.getSystem()
+
+ # get enum value
+ print ("get enum value (DiscoveryCameraEvent): '%s'" % (system.DiscoveryCameraEvent))
+
+ # get enum range
+ range = system.getFeatureRange('DiscoveryCameraEvent')
+ print ("get enum value range (DiscoveryCameraEvent): '%s'" % (str(range)))
+
+ # set enum value
+ #print ("setting enum value (DiscoveryCameraEvent)...")
+ #system.DiscoveryCameraEvent = 'Unreachable'
+ #print ("enum value (DiscoveryCameraEvent)set to '%s'." % (system.DiscoveryCameraEvent.value))
+
+
+if __name__ == '__main__':
+ test_enumfeature() \ No newline at end of file
diff --git a/tests/test_installation.py b/tests/test_installation.py
new file mode 100644
index 0000000..06af7d6
--- /dev/null
+++ b/tests/test_installation.py
@@ -0,0 +1,9 @@
+#!/usr/bin/python
+from __future__ import absolute_import, print_function, division
+from pymba import Vimba
+
+
+def test_installation():
+ with Vimba() as vimba:
+ version = vimba.getVersion()
+ assert version == '1.2.0'
diff --git a/tests/test_interfaces.py b/tests/test_interfaces.py
new file mode 100644
index 0000000..270d42c
--- /dev/null
+++ b/tests/test_interfaces.py
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+from __future__ import absolute_import, print_function, division
+from pymba import *
+import time
+
+
+def test_interfaces():
+ # start Vimba
+ with Vimba() as vimba:
+ # 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()
+
+if __name__ == '__main__':
+ test_interfaces() \ No newline at end of file
diff --git a/tests/test_systemfeature.py b/tests/test_systemfeature.py
new file mode 100644
index 0000000..abb4da7
--- /dev/null
+++ b/tests/test_systemfeature.py
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+from __future__ import absolute_import, print_function, division
+from pymba import *
+
+
+def test_systemfeature():
+ # get system object
+ with Vimba() as vimba:
+ system = vimba.getSystem()
+
+ # list system features
+ for featureName in system.getFeatureNames():
+ print('System feature:', featureName)
+ fInfo = system.getFeatureInfo(featureName)
+ for field in fInfo.getFieldNames():
+ print("\t", featureName, ":", field, getattr(fInfo, field))
+
+
+if __name__ == '__main__':
+ test_systemfeature() \ No newline at end of file