diff options
| author | François-Michel De Rainville <f.derainville@gmail.com> | 2015-01-26 08:21:07 -0500 |
|---|---|---|
| committer | François-Michel De Rainville <f.derainville@gmail.com> | 2015-01-26 08:21:07 -0500 |
| commit | db6f460d33e421c59ea588a43f10815cf7c0abe8 (patch) | |
| tree | 6a4628b054e119d39af940d642a1da92890b0a24 | |
| parent | 25fbd475e4f4f4cc3905f024f521da7fecf4339c (diff) | |
| download | pymba-db6f460d33e421c59ea588a43f10815cf7c0abe8.tar.gz pymba-db6f460d33e421c59ea588a43f10815cf7c0abe8.zip | |
Updated README to use the with statement
| -rw-r--r-- | README.txt | 177 |
1 files changed, 85 insertions, 92 deletions
@@ -23,8 +23,8 @@ If Vimba SDK and pymba are installed correctly, then the following code should g from vimba import * - vimba = Vimba() - print vimba.getVersion() + with Vimba() as vimba: + print vimba.getVersion() Interacting with cameras ------------------------ @@ -35,69 +35,63 @@ Discover, open, manipulate, and capture frames from a camera. import time # 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() + 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 Interacting with the Vimba system --------------------------------- @@ -106,15 +100,14 @@ Get a reference to the Vimba system object and list available system features. from vimba import * - # get system object - system = vimba.getSystem() - - # list system features - for featureName in system.getFeatureNames(): - print 'System feature:', featureName + with Vimba() as vimba: + # get system object + system = vimba.getSystem() + + # list system features + for featureName in system.getFeatureNames(): + print 'System feature:', featureName - # shutdown Vimba - vimba.shutdown() Interacting with transport layer interfaces ------------------------------------------- @@ -123,22 +116,23 @@ Get a reference to an interface object and list available interface features. from vimba import * - # 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() + 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() Handling Vimba exceptions ------------------------- @@ -146,10 +140,9 @@ Handling Vimba exceptions from vimba import * try: - vimba = Vimba() - vimba.startup() + with Vimba() as vimba: except VimbaException as e: - print e.message + print e.message Known issues ============ |
