cvb/StreamingAsync
1 # CVBpy Example Script
2 #
3 # 1. Open the CVMock.vin driver.
4 # 2. Asynchronously acquire images.
5 # 3. Measure the frame rate and print results.
6 #
7 # Note: can be extended to multible cameras.
8 
9 
10 import os
11 import asyncio
12 import cvb
13 
14 
15 
16 
17 rate_counter = None
18 
19 async def async_acquire(port):
20  global rate_counter
21  with cvb.DeviceFactory.open(os.path.join(cvb.install_path(), "drivers", "CVMock.vin"), port=port) as device:
22  stream = device.stream()
23  stream.start()
24 
25  rate_counter = cvb.RateCounter()
26 
27  for i in range(0, 100):
28  result = await stream.wait_async()
29  image, status = result.value
30  rate_counter.step()
31  if status == cvb.WaitStatus.Ok:
32  print("Buffer index: " + str(image.buffer_index) + " from stream: " + str(port))
33 
34  stream.abort()
35 
36 
37 
38 
39 watch = cvb.StopWatch()
40 
41 loop = asyncio.get_event_loop()
42 loop.run_until_complete(asyncio.gather(
43  async_acquire(port=0)))
44 loop.close()
45 
46 duration = watch.time_span
47 
48 print("Acquired on port 0 with " + str(rate_counter.rate) + " fps")
49 print("Overall measurement time: " +str(duration / 1000) + " seconds")
50 
51 
Speed measurement object.
Definition: __init__.py:4604
Frame rate measurement counter with selectable averaging window.
Definition: __init__.py:4033
Union[cvb.GenICamDevice, cvb.VinDevice, cvb.EmuDevice, cvb.VideoDevice, cvb.NonStreamingDevice] open(str provider, int acquisition_stack=cvb.AcquisitionStack.PreferVin)
Opens a device with the given provider and acquisition stack.
Definition: __init__.py:1327
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:7153