1import os, platform, sys
2
3from mvIMPACT import acquire
4
5
7
8
9
10
11class EventCallback(acquire.ComponentCallback):
12 def __init__(self, pUserData):
13 acquire.ComponentCallback.__init__(self)
14 self.pUserData_ = pUserData
15
16 def execute(self, c, pUserData):
17 try:
18
19 ec = self.pUserData_
20 if( c.isProp ):
21 p = acquire.Property(c.hObj())
22 print("Component " + c.name() + " has changed. Its current value: " + p.readS() + "us. FrameID is: " + ec.eventExposureEndFrameID.readS())
23 except Exception as e:
24 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!")
25
26devMgr = acquire.DeviceManager()
27pDev = exampleHelper.getDeviceFromUserInput(devMgr)
28if pDev == None:
29 exampleHelper.requestENTERFromUser()
30 sys.exit(-1)
31pDev.open()
32
33print("Please enter the number of buffers to capture followed by [ENTER]: ", end='')
34framesToCapture = exampleHelper.getNumberFromUser()
35if framesToCapture < 1:
36 print("Invalid input! Please capture at least one image")
37 sys.exit(-1)
38
39
40isDisplayModuleAvailable = platform.system() == "Windows"
41if isDisplayModuleAvailable:
42 display = acquire.ImageDisplayWindow("A window created from Python")
43else:
44 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.")
45
46fi = acquire.FunctionInterface(pDev)
47
48while fi.imageRequestSingle() == acquire.DMR_NO_ERROR:
49 print("Buffer queued")
50pPreviousRequest = None
51
52
53ec = acquire.EventControl(pDev)
54ec.eventSelector.writeS("ExposureEnd")
55ec.eventNotification.writeS("On")
56
57
58eventCallback = EventCallback(ec)
59eventCallback.registerComponent(ec.eventExposureEndTimestamp)
60
61exampleHelper.manuallyStartAcquisitionIfNeeded(pDev, fi)
62for i in range(framesToCapture):
63 requestNr = fi.imageRequestWaitFor(10000)
64 if fi.isRequestNrValid(requestNr):
65 pRequest = fi.getRequest(requestNr)
66 if pRequest.isOK:
67 if isDisplayModuleAvailable:
68 display.GetImageDisplay().SetImage(pRequest)
69 display.GetImageDisplay().Update()
70 if pPreviousRequest != None:
71 pPreviousRequest.unlock()
72 pPreviousRequest = pRequest
73 fi.imageRequestSingle()
74 else:
75
76
77
78
79
80
81
82
83
84
85 print("imageRequestWaitFor failed (" + str(requestNr) + ", " + acquire.ImpactAcquireException.getErrorCodeAsString(requestNr) + ")")
86exampleHelper.manuallyStopAcquisitionIfNeeded(pDev, fi)
87eventCallback.unregisterComponent( ec.eventExposureEndTimestamp)
88exampleHelper.requestENTERFromUser()
Definition Common/__init__.py:1