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 82 83 84
|
#!/usr/bin/env python3
# SPDX-License-Identifier:Unlicense
# If you have installed aravis in a non standard location, you may need
# to make GI_TYPELIB_PATH point to the correct location. For example:
#
# export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:/opt/bin/lib/girepositry-1.0/
#
# You may also have to give the path to libaravis.so, using LD_PRELOAD or
# LD_LIBRARY_PATH.
import sys
import gi
import signal
gi.require_version('Aravis', '0.8')
from gi.repository import Aravis,GLib
class SIGINT_handler():
def __init__(self):
self.SIGINT = False
def signal_handler(self, signal, frame):
print('You pressed Ctrl+C!')
self.SIGINT = True
handler = SIGINT_handler()
signal.signal(signal.SIGINT, handler.signal_handler)
try:
if len(sys.argv) > 1:
print ("Looking for camera '" + sys.argv[1] + "'");
camera = Aravis.Camera.new (sys.argv[1])
else:
print ("Looking for the first available camera");
camera = Aravis.Camera.new (None)
except GLib.Error as err:
print ("No camera found: " + err.message)
exit ()
camera.set_region(0, 0, 100, 100)
camera.set_frame_rate(20.0)
region = camera.get_region()
print("vendor name = " + camera.get_vendor_name())
print("model name = " + camera.get_model_name())
print("region = {0}".format(region))
stream = camera.create_stream()
payload = camera.get_payload()
for i in range(10):
stream.push_buffer(Aravis.Buffer.new(payload))
camera.start_acquisition()
counter=0
while not handler.SIGINT:
buffer = stream.timeout_pop_buffer(1000000)
if buffer != None:
print("Buffer {0}x{0} {1}".format(buffer.get_image_width(), buffer))
stream.push_buffer(buffer)
if counter % 10 == 0:
width = ((counter / 10) % 2 + 1) * 100
print (width)
camera.stop_acquisition()
stream.stop_thread(True)
camera.set_region(0, 0, width, width)
payload = camera.get_payload()
for i in range(10):
stream.push_buffer(Aravis.Buffer.new(payload))
stream.start_thread()
camera.start_acquisition()
counter = counter + 1
camera.stop_acquisition()
|