GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — VimbaPython Beta Release · alliedvision/VimbaPython@82571be

This repository was archived by the owner on Apr 18, 2024. It is now read-only.

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Documentation
    • Vimba Python Manual.pdf
  • Examples
    • action_commands.py
    • asynchronous_grab.py
    • asynchronous_grab_opencv.py
    • create_trace_log.py
    • event_handling.py
    • list_ancillary_data.py
    • list_cameras.py
    • list_features.py
    • load_save_settings.py
    • synchronous_grab.py
    • user_set.py
  • LICENSE.txt
  • README.md
  • Test
    • real_cam_tests
      • camera_test.py
      • feature_test.py
      • frame_test.py
      • vimba_test.py
    • runner.py
    • tests
      • c_binding_test.py
      • util_runtime_type_check_test.py
      • util_tracer_test.py
      • vimba_test.py
  • run_tests.py
  • setup.cfg
  • setup.py
  • vimba
    • __init__.py
    • c_binding
      • __init__.py
      • vimba_c.py
      • vimba_common.py
      • vimba_image_transform.py
    • camera.py
    • error.py
    • feature.py
    • frame.py
    • interface.py
    • shared.py
    • util
      • __init__.py
      • log.py
      • runtime_type_check.py
      • scoped_log.py
      • tracer.py
    • vimba.py

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Documentation/Vimba Python Manual.pdf‎

Copy file name to clipboard
149 KB
Binary file not shown.
Collapse file

‎Examples/action_commands.py‎

Copy file name to clipboard
+193Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
"""BSD 2-Clause License
2+
3+
Copyright (c) 2019, Allied Vision Technologies GmbH
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
THE SOFTWARE IS PRELIMINARY AND STILL IN TESTING AND VERIFICATION PHASE AND
28+
IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS AND IS BELIEVED TO CONTAIN DEFECTS.
29+
A PRIMARY PURPOSE OF THIS EARLY ACCESS IS TO OBTAIN FEEDBACK ON PERFORMANCE AND
30+
THE IDENTIFICATION OF DEFECT SOFTWARE, HARDWARE AND DOCUMENTATION.
31+
"""
32+
33+
import sys
34+
from typing import Tuple
35+
from vimba import *
36+
37+
38+
def print_preamble():
39+
print('/////////////////////////////////////////')
40+
print('/// Vimba API Action Commands Example ///')
41+
print('/////////////////////////////////////////\n')
42+
43+
44+
def print_usage():
45+
print('Usage:')
46+
print(' python action_commands.py <camera_id> <interface_id>')
47+
print(' python action_commands.py [/h] [-h]')
48+
print()
49+
print('Parameters:')
50+
print(' camera_id ID of the camera to be used')
51+
print(' interface_id ID of network interface to send out Action Command')
52+
print(' \'ALL\' enables broadcast on all interfaces')
53+
print()
54+
55+
56+
def abort(reason: str, return_code: int = 1, usage: bool = False):
57+
print(reason + '\n')
58+
59+
if usage:
60+
print_usage()
61+
62+
sys.exit(return_code)
63+
64+
65+
def parse_args() -> Tuple[str, str]:
66+
args = sys.argv[1:]
67+
68+
for arg in args:
69+
if arg in ('/h', '-h'):
70+
print_usage()
71+
sys.exit(0)
72+
73+
if len(args) != 2:
74+
abort(reason="Invalid number of arguments. Abort.", return_code=2, usage=True)
75+
76+
return (args[0], args[1])
77+
78+
79+
def get_input() -> str:
80+
prompt = 'Press \'a\' to send action command. Press \'q\' to stop example. Enter:'
81+
print(prompt, flush=True)
82+
return input()
83+
84+
85+
def get_camera(camera_id: str) -> Camera:
86+
with Vimba.get_instance() as vimba:
87+
try:
88+
return vimba.get_camera_by_id(camera_id)
89+
90+
except VimbaCameraError:
91+
abort('Failed to access Camera {}. Abort.'.format(camera_id))
92+
93+
94+
def get_command_sender(interface_id):
95+
# If given interface_id is ALL, ActionCommand shall be sent from all Ethernet Interfaces.
96+
# This is achieved by run ActionCommand on the Vimba instance.
97+
if interface_id == 'ALL':
98+
return Vimba.get_instance()
99+
100+
with Vimba.get_instance() as vimba:
101+
# A specific Interface was given. Lookup via given Interface id and verify that
102+
# it is an Ethernet Interface. Running ActionCommand will be only send from this Interface.
103+
try:
104+
inter = vimba.get_interface_by_id(interface_id)
105+
106+
except VimbaInterfaceError:
107+
abort('Failed to access Interface {}. Abort.'.format(interface_id))
108+
109+
if inter.get_type() != InterfaceType.Ethernet:
110+
abort('Given Interface {} is no Ethernet Interface. Abort.'.format(interface_id))
111+
112+
return inter
113+
114+
115+
def set_feature(entity, feature_name: str, feature_value):
116+
try:
117+
entity.get_feature_by_name(feature_name).set(feature_value)
118+
119+
except VimbaFeatureError:
120+
abort('Could not set Feature \'{}\'. Abort.'.format(feature_name))
121+
122+
123+
def command_run(entity, feature_name: str):
124+
try:
125+
entity.get_feature_by_name(feature_name).run()
126+
127+
except VimbaFeatureError:
128+
abort('Failed to run Feature \'{}\'. Abort.'.format(feature_name))
129+
130+
131+
def command_run_and_wait(entity, feature_name: str):
132+
try:
133+
cmd_feat = entity.get_feature_by_name(feature_name)
134+
cmd_feat.run()
135+
136+
while not cmd_feat.is_done():
137+
pass
138+
139+
except VimbaFeatureError:
140+
abort('Failed to run Feature \'{}\'. Abort.'.format(feature_name))
141+
142+
143+
def frame_handler(cam: Camera, frame: Frame):
144+
if frame.get_status() == FrameStatus.Complete:
145+
print('Frame(ID: {}) has been received.'.format(frame.get_id()), flush=True)
146+
147+
cam.queue_frame(frame)
148+
149+
150+
def main():
151+
print_preamble()
152+
camera_id, interface_id = parse_args()
153+
154+
with Vimba.get_instance():
155+
cam = get_camera(camera_id)
156+
sender = get_command_sender(interface_id)
157+
158+
with cam, sender:
159+
# Prepare Camera for ActionCommand - Trigger
160+
device_key = 1
161+
group_key = 1
162+
group_mask = 1
163+
164+
command_run_and_wait(cam, 'GVSPAdjustPacketSize')
165+
set_feature(cam, 'TriggerSelector', 'FrameStart')
166+
set_feature(cam, 'TriggerSource', 'Action0')
167+
set_feature(cam, 'TriggerMode', 'On')
168+
set_feature(cam, 'ActionDeviceKey', device_key)
169+
set_feature(cam, 'ActionGroupKey', group_key)
170+
set_feature(cam, 'ActionGroupMask', group_mask)
171+
172+
# Enter Streaming mode and wait for user input.
173+
try:
174+
cam.start_streaming(frame_handler)
175+
176+
while True:
177+
ch = get_input()
178+
179+
if ch == 'q':
180+
break
181+
182+
elif ch == 'a':
183+
set_feature(sender, 'ActionDeviceKey', device_key)
184+
set_feature(sender, 'ActionGroupKey', group_key)
185+
set_feature(sender, 'ActionGroupMask', group_mask)
186+
command_run(sender, 'ActionCommand')
187+
188+
finally:
189+
cam.stop_streaming()
190+
191+
192+
if __name__ == '__main__':
193+
main()
Collapse file

‎Examples/asynchronous_grab.py‎

Copy file name to clipboard
+140Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
"""BSD 2-Clause License
2+
3+
Copyright (c) 2019, Allied Vision Technologies GmbH
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
THE SOFTWARE IS PRELIMINARY AND STILL IN TESTING AND VERIFICATION PHASE AND
28+
IS PROVIDED ON AN “AS IS” AND “AS AVAILABLE” BASIS AND IS BELIEVED TO CONTAIN DEFECTS.
29+
A PRIMARY PURPOSE OF THIS EARLY ACCESS IS TO OBTAIN FEEDBACK ON PERFORMANCE AND
30+
THE IDENTIFICATION OF DEFECT SOFTWARE, HARDWARE AND DOCUMENTATION.
31+
"""
32+
33+
import sys
34+
from typing import Optional
35+
from vimba import *
36+
37+
38+
def print_preamble():
39+
print('///////////////////////////////////////////')
40+
print('/// Vimba API Asynchronous Grab Example ///')
41+
print('///////////////////////////////////////////\n')
42+
43+
44+
def print_usage():
45+
print('Usage:')
46+
print(' python asynchronous_grab.py [camera_id]')
47+
print(' python asynchronous_grab.py [/h] [-h]')
48+
print()
49+
print('Parameters:')
50+
print(' camera_id ID of the camera to use (using first camera if not specified)')
51+
print()
52+
53+
54+
def abort(reason: str, return_code: int = 1, usage: bool = False):
55+
print(reason + '\n')
56+
57+
if usage:
58+
print_usage()
59+
60+
sys.exit(return_code)
61+
62+
63+
def parse_args() -> Optional[str]:
64+
args = sys.argv[1:]
65+
argc = len(args)
66+
67+
for arg in args:
68+
if arg in ('/h', '-h'):
69+
print_usage()
70+
sys.exit(0)
71+
72+
if argc > 1:
73+
abort(reason="Invalid number of arguments. Abort.", return_code=2, usage=True)
74+
75+
return None if argc == 0 else args[0]
76+
77+
78+
def get_camera(camera_id: Optional[str]) -> Camera:
79+
with Vimba.get_instance() as vimba:
80+
if camera_id:
81+
try:
82+
return vimba.get_camera_by_id(camera_id)
83+
84+
except VimbaCameraError:
85+
abort('Failed to access Camera \'{}\'. Abort.'.format(camera_id))
86+
87+
else:
88+
cams = vimba.get_all_cameras()
89+
if not cams:
90+
abort('No Cameras accessible. Abort.')
91+
92+
return cams[0]
93+
94+
95+
def setup_camera(cam: Camera):
96+
with cam:
97+
# Try to adjust GeV packet size. This Feature is only available for GigE - Cameras.
98+
try:
99+
cmd_feat = cam.get_feature_by_name('GVSPAdjustPacketSize')
100+
101+
try:
102+
cmd_feat.run()
103+
104+
while not cmd_feat.is_done():
105+
pass
106+
107+
except VimbaFeatureError:
108+
abort('Failed to set Feature \'GVSPAdjustPacketSize\'. Abort.')
109+
110+
except VimbaFeatureError:
111+
pass
112+
113+
114+
def frame_handler(cam: Camera, frame: Frame):
115+
print('{} acquired {}'.format(cam, frame), flush=True)
116+
117+
cam.queue_frame(frame)
118+
119+
120+
def main():
121+
print_preamble()
122+
cam_id = parse_args()
123+
124+
with Vimba.get_instance():
125+
with get_camera(cam_id) as cam:
126+
127+
setup_camera(cam)
128+
print('Press <enter> to stop Frame acquisition.')
129+
130+
try:
131+
# Start Streaming with a custom a buffer of 10 Frames (defaults to 5)
132+
cam.start_streaming(handler=frame_handler, buffer_count=10)
133+
input()
134+
135+
finally:
136+
cam.stop_streaming()
137+
138+
139+
if __name__ == '__main__':
140+
main()

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.