-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasler_test.py
81 lines (64 loc) · 2.79 KB
/
basler_test.py
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
70
71
72
73
74
75
76
77
78
79
80
81
from pypylon import pylon
from pypylon import genicam
import sys
def grab(camera):
# Number of images to be grabbed.
countOfImagesToGrab = 100
# The exit code of the sample application.
exitCode = 0
try:
# 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
new_width = camera.Width.GetValue() - camera.Width.GetInc()
if new_width >= camera.Width.GetMin():
camera.Width.SetValue(new_width)
# 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
# Start the grabbing of c_countOfImagesToGrab images.
# The camera device is parameterized with a default configuration which
# sets up free-running continuous acquisition.
camera.StartGrabbingMax(countOfImagesToGrab)
# Camera.StopGrabbing() is called automatically by the RetrieveResult() method
# when c_countOfImagesToGrab images have been retrieved.
while camera.IsGrabbing():
# Wait for an image and then retrieve it. A timeout of 5000 ms is used.
grabResult = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)
# Image grabbed successfully?
if grabResult.GrabSucceeded():
# Access the image data.
print("SizeX: ", grabResult.Width)
print("SizeY: ", grabResult.Height)
img = grabResult.Array
print("Gray value of first pixel: ", img[0, 0])
else:
print("Error: ", grabResult.ErrorCode, grabResult.ErrorDescription)
grabResult.Release()
camera.Close()
except genicam.GenericException as e:
# Error handling.
print("An exception occurred.")
# print(e.GetDescription())
exitCode = 1
sys.exit(exitCode)
def main():
factory = pylon.TlFactory.GetInstance()
ptl = factory.CreateTl('BaslerGigE')
empty_camera_info = ptl.CreateDeviceInfo()
ip = '10.223.109.131'
empty_camera_info.SetPropertyValue('IpAddress', ip)
camera_device = factory.CreateDevice(empty_camera_info)
cam_obj = pylon.InstantCamera(camera_device)
grab(cam_obj)
def backup():
ip_address = '10.223.109.131'
info = pylon.DeviceInfo()
info.SetPropertyValue('IpAddress', ip_address)
print(info.GetPropertyNames())
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice(info))
grab(camera)
backup()