Impact Acquire SDK Python
ContinuousCapture.py

The ContinuousCapture program is a simple example for a continuous acquisition.

Program location
The source file ContinuousCapture.py can be found under:
%INSTALLDIR%\apps\Python\ContinuousCapture\
Note
If you have installed the package without example applications, this file will not be available. On Windows® the sample application can be installed or removed from the target system at any time by simply restarting the installation package.
ContinuousCapture example:
  1. Opens a Balluff device.
  2. Snaps images continuously (without display using Linux).
Console Output
[0]: BF000306 (mvBlueFOX-202C, Family: mvBlueFOX, interface layout: DeviceSpecific)

Please enter the number in front of the listed device followed by [ENTER] to open it: 0
Using device number 0.
Press [ENTER] to end the application
Initialising the device. This might take some time...
Info from BF000306: FramesPerSecond: 28.655660, ErrorCount: 0, CaptureTime_s: 0.104195
Info from BF000306: FramesPerSecond: 28.655636, ErrorCount: 0, CaptureTime_s: 0.104017
Info from BF000306: FramesPerSecond: 28.655659, ErrorCount: 0, CaptureTime_s: 0.104153
Info from BF000306: FramesPerSecond: 28.655636, ErrorCount: 0, CaptureTime_s: 0.104072
Info from BF000306: FramesPerSecond: 28.655660, ErrorCount: 0, CaptureTime_s: 0.104234
How it works

The continuous acquisition starts a thread that continuously requests images from the device.

First of all the user is prompted to select the device he wants to use for this sample:

pDev = devMgr.getDevice(devNr)
pDev.open()

Then after the device has been initialized successfully a continuous acquisition is started via the exampleHelper.

Accessing the pRequest object can be done after it has been checked using the pRequest.isOK function. The image attached to the request can then be processed and/or displayed if the request does not report an error.

requestNr = fi.imageRequestWaitFor(10000)
if fi.isRequestNrValid(requestNr):
pRequest = fi.getRequest(requestNr)
if pRequest.isOK:
...
Source code
1import os, platform, sys
2# import all the stuff from our SDK into the current scope
3from mvIMPACT import acquire
4# import all the helper functions for the examples using our SDK such as 'conditionalSetProperty' into the current scope
5# If you want to use this module in your code feel free to do so but make sure the 'Common' folder resides in a sub-folder of your project then
6from mvIMPACT.Common import exampleHelper
7
8# For systems with NO mvDisplay library support
9#import ctypes
10#import Image
11#import numpy
12
13devMgr = acquire.DeviceManager()
14pDev = exampleHelper.getDeviceFromUserInput(devMgr)
15if pDev == None:
16 exampleHelper.requestENTERFromUser()
17 sys.exit(-1)
18pDev.open()
19
20print("Please enter the number of buffers to capture followed by [ENTER]: ", end='')
21framesToCapture = exampleHelper.getNumberFromUser()
22if framesToCapture < 1:
23 print("Invalid input! Please capture at least one image")
24 sys.exit(-1)
25
26# The mvDisplay library is only available on Windows systems for now
27isDisplayModuleAvailable = platform.system() == "Windows"
28if isDisplayModuleAvailable:
29 display = acquire.ImageDisplayWindow("A window created from Python")
30else:
31 print("The display library of this SDK is not available on this('" + platform.system() + "') system. Consider using the PIL(Python Image Library) and numpy(Numerical Python) packages instead. Have a look at the source code of this application to get an idea how.")
32
33fi = acquire.FunctionInterface(pDev)
34statistics = acquire.Statistics(pDev)
35
36while fi.imageRequestSingle() == acquire.DMR_NO_ERROR:
37 print("Buffer queued")
38pPreviousRequest = None
39
40exampleHelper.manuallyStartAcquisitionIfNeeded(pDev, fi)
41for i in range(framesToCapture):
42 requestNr = fi.imageRequestWaitFor(10000)
43 if fi.isRequestNrValid(requestNr):
44 pRequest = fi.getRequest(requestNr)
45 if pRequest.isOK:
46 if i%100 == 0:
47 print("Info from " + pDev.serial.read() +
48 ": " + statistics.framesPerSecond.name() + ": " + statistics.framesPerSecond.readS() +
49 ", " + statistics.errorCount.name() + ": " + statistics.errorCount.readS() +
50 ", " + statistics.captureTime_s.name() + ": " + statistics.captureTime_s.readS())
51 if isDisplayModuleAvailable:
52 display.GetImageDisplay().SetImage(pRequest)
53 display.GetImageDisplay().Update()
54 # For systems with NO mvDisplay library support
55 #cbuf = (ctypes.c_char * pRequest.imageSize.read()).from_address(int(pRequest.imageData.read()))
56 #channelType = numpy.uint16 if pRequest.imageChannelBitDepth.read() > 8 else numpy.uint8
57 #arr = numpy.fromstring(cbuf, dtype = channelType)
58 #arr.shape = (pRequest.imageHeight.read(), pRequest.imageWidth.read(), pRequest.imageChannelCount.read())
59
60 #if channelCount == 1:
61 # img = Image.fromarray(arr)
62 #else:
63 # img = Image.fromarray(arr, 'RGBA' if alpha else 'RGB')
64 if pPreviousRequest != None:
65 pPreviousRequest.unlock()
66 pPreviousRequest = pRequest
67 fi.imageRequestSingle()
68 else:
69 # Please note that slow systems or interface technologies in combination with high resolution sensors
70 # might need more time to transmit an image than the timeout value which has been passed to imageRequestWaitFor().
71 # If this is the case simply wait multiple times OR increase the timeout(not recommended as usually not necessary
72 # and potentially makes the capture thread less responsive) and rebuild this application.
73 # Once the device is configured for triggered image acquisition and the timeout elapsed before
74 # the device has been triggered this might happen as well.
75 # The return code would be -2119(DEV_WAIT_FOR_REQUEST_FAILED) in that case, the documentation will provide
76 # additional information under TDMR_ERROR in the interface reference.
77 # If waiting with an infinite timeout(-1) it will be necessary to call 'imageRequestReset' from another thread
78 # to force 'imageRequestWaitFor' to return when no data is coming from the device/can be captured.
79 print("imageRequestWaitFor failed (" + str(requestNr) + ", " + acquire.ImpactAcquireException.getErrorCodeAsString(requestNr) + ")")
80exampleHelper.manuallyStopAcquisitionIfNeeded(pDev, fi)
81exampleHelper.requestENTERFromUser()
Definition Common/__init__.py:1