aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authormorefigs <morefigs@gmail.com>2019-01-30 15:12:13 +1100
committermorefigs <morefigs@gmail.com>2019-01-30 15:12:13 +1100
commit8001a079833ff96b855cb6f618b1c23a5b05ad7d (patch)
treec145667c5e9d32d90655689549d1072c0af1a61b /tests
parent87a55df00f138e0b3f5b8469c2a43f868704426c (diff)
parent7a915f3af6af7a3a8ef6c9d28aeb87392df3c8b4 (diff)
downloadpymba-8001a079833ff96b855cb6f618b1c23a5b05ad7d.tar.gz
pymba-8001a079833ff96b855cb6f618b1c23a5b05ad7d.zip
v0.2 to master
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
-rw-r--r--tests/test_vimba.py52
10 files changed, 52 insertions, 398 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/tests/__init__.py
+++ /dev/null
diff --git a/tests/opencv_example.py b/tests/opencv_example.py
deleted file mode 100644
index 238e8b4..0000000
--- a/tests/opencv_example.py
+++ /dev/null
@@ -1,76 +0,0 @@
-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
deleted file mode 100644
index 78b6b67..0000000
--- a/tests/opencv_liveview_example.py
+++ /dev/null
@@ -1,79 +0,0 @@
-# -*- 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
deleted file mode 100644
index fd7a819..0000000
--- a/tests/opencv_liveview_example_color.py
+++ /dev/null
@@ -1,89 +0,0 @@
-# -*- 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
deleted file mode 100644
index a5a4dd9..0000000
--- a/tests/test_cameras.py
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/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
deleted file mode 100644
index 7f9dd4c..0000000
--- a/tests/test_enumfeature.py
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/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
deleted file mode 100644
index 06af7d6..0000000
--- a/tests/test_installation.py
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/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
deleted file mode 100644
index 270d42c..0000000
--- a/tests/test_interfaces.py
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/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
deleted file mode 100644
index abb4da7..0000000
--- a/tests/test_systemfeature.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/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
diff --git a/tests/test_vimba.py b/tests/test_vimba.py
new file mode 100644
index 0000000..b1ef987
--- /dev/null
+++ b/tests/test_vimba.py
@@ -0,0 +1,52 @@
+import pytest
+
+from pymba import Vimba, VimbaException
+
+
+def test_version():
+ version = Vimba().version.split('.')
+ assert int(version[0]) >= 1
+ assert int(version[1]) >= 7
+ assert int(version[2]) >= 0
+
+
+def test_startup_shutdown():
+ with pytest.raises(VimbaException) as e:
+ Vimba().system().feature_names()
+ assert e.value.error_code == VimbaException.ERR_STARTUP_NOT_CALLED
+
+ # manual
+ Vimba().startup()
+ Vimba().system().feature_names()
+ Vimba().shutdown()
+
+ # context manager
+ with Vimba() as vmb:
+ vmb.system().feature_names()
+
+
+@pytest.fixture
+def vimba() -> Vimba:
+ with Vimba() as vimba:
+ # for ethernet camera discovery
+ if vimba.system().GeVTLIsPresent:
+ vimba.system().run_feature_command("GeVDiscoveryAllOnce")
+ yield vimba
+
+
+def test_interface_camera_ids(vimba: Vimba):
+ # test id funcs return a list of strings (not bytes)
+ for func in (vimba.interface_ids, vimba.camera_ids):
+ ids = func()
+ assert isinstance(ids, list)
+ assert ids
+ for x in ids:
+ assert isinstance(x, str)
+
+
+def test_interface(vimba: Vimba):
+ interface = vimba.interface(vimba.interface_ids()[0])
+
+
+def test_camera(vimba: Vimba):
+ camera = vimba.camera(vimba.camera_ids()[0])