import os, platform, sys
from mvIMPACT import acquire
class EventCallback(acquire.ComponentCallback):
def __init__(self, pUserData):
acquire.ComponentCallback.__init__(self)
self.pUserData_ = pUserData
def execute(self, c, pUserData):
try:
ec = self.pUserData_
if( c.isProp ):
p = acquire.Property(c.hObj())
print("Component " + c.name() + " has changed. Its current value: " + p.readS() + "us. FrameID is: " + ec.eventExposureEndFrameID.readS())
except Exception as e:
print("An exception has been raised by code that is not supposed to raise one: '" + str(e) + "'! If this is NOT handled here the application will crash as this Python exception instance will be returned back into the native code that fired the callback!")
devMgr = acquire.DeviceManager()
pDev = exampleHelper.getDeviceFromUserInput(devMgr)
if pDev == None:
exampleHelper.requestENTERFromUser()
sys.exit(-1)
pDev.open()
print("Please enter the number of buffers to capture followed by [ENTER]: ", end='')
framesToCapture = exampleHelper.getNumberFromUser()
if framesToCapture < 1:
print("Invalid input! Please capture at least one image")
sys.exit(-1)
isDisplayModuleAvailable = platform.system() == "Windows"
if isDisplayModuleAvailable:
display = acquire.ImageDisplayWindow("A window created from Python")
else:
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 the ContinuousCapture example to get an idea how.")
fi = acquire.FunctionInterface(pDev)
while fi.imageRequestSingle() == acquire.DMR_NO_ERROR:
print("Buffer queued")
pPreviousRequest = None
ec = acquire.EventControl(pDev)
ec.eventSelector.writeS("ExposureEnd")
ec.eventNotification.writeS("On")
eventCallback = EventCallback(ec)
eventCallback.registerComponent(ec.eventExposureEndTimestamp)
exampleHelper.manuallyStartAcquisitionIfNeeded(pDev, fi)
for i in range(framesToCapture):
requestNr = fi.imageRequestWaitFor(10000)
if fi.isRequestNrValid(requestNr):
pRequest = fi.getRequest(requestNr)
if pRequest.isOK:
if isDisplayModuleAvailable:
display.GetImageDisplay().SetImage(pRequest)
display.GetImageDisplay().Update()
if pPreviousRequest != None:
pPreviousRequest.unlock()
pPreviousRequest = pRequest
fi.imageRequestSingle()
else:
print("imageRequestWaitFor failed (" + str(requestNr) + ", " + acquire.ImpactAcquireException.getErrorCodeAsString(requestNr) + ")")
exampleHelper.manuallyStopAcquisitionIfNeeded(pDev, fi)
eventCallback.unregisterComponent( ec.eventExposureEndTimestamp)
exampleHelper.requestENTERFromUser()
Definition Common/__init__.py:1