-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrab_using_externel_trigger.py
More file actions
69 lines (54 loc) · 2.12 KB
/
grab_using_externel_trigger.py
File metadata and controls
69 lines (54 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from pypylon import pylon
from pypylon import genicam
import numpy
def main():
imageWindow = pylon.PylonImageWindow()
imageWindow.Create(1)
# Create an instant camera object with the camera device found first.
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
camera.Open()
# Print the model name of the camera.
print("Using device ", camera.GetDeviceInfo().GetModelName())
# demonstrate some feature access
# The parameter MaxNumBuffer can be used to control the count of buffers
# allocated for grabbing. The default value of this parameter is 10.
camera.MaxNumBuffer = 5
camera.TriggerSelector.Value = "FrameStart"
camera.TriggerMode.Value = "On"
camera.TriggerSource.Value = "Line1"
# Start the grabbing of c_countOfImagesToGrab images.
# The camera device is parameterized with a default configuration which
# sets up free-running continuous acquisition.
camera.StartGrabbing(pylon.GrabStrategy_OneByOne)
clear_buffer(camera)
while camera.IsGrabbing():
if camera.WaitForFrameTriggerReady(200, pylon.TimeoutHandling_ThrowException):
continue
# Wait for an image and then retrieve it. A timeout of 5000 ms is used.
grabResult = camera.RetrieveResult(200, pylon.TimeoutHandling_ThrowException)
try:
# Image grabbed successfully?
if grabResult.GrabSucceeded():
imageWindow.SetImage(grabResult)
imageWindow.Show()
else:
print("Error: ", grabResult.ErrorCode, grabResult.ErrorDescription)
except genicam.GenericException as e:
# Error handling.
print("An exception occurred.")
print(e.GetDescription())
finally:
grabResult.Release()
camera.Close()
imageWindow.Close()
r"""
Clear buffer in camera queue.
"""
def clear_buffer(camera):
while camera.NumReadyBuffers.GetValue() > 0:
camera.RetrieveResult(5000, pylon.TimeoutHandling_Return)
if __name__ == "__main__":
try:
main()
except Exception as e:
print(str(e))