CVBpy 15.0
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
10import os
11import asyncio
12import cvb
13
14
15
16
17rate_counter = None
18
19async 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
39watch = cvb.StopWatch()
40
41loop = asyncio.get_event_loop()
42loop.run_until_complete(asyncio.gather(
43 async_acquire(port=0)))
44loop.close()
45
46duration = watch.time_span
47
48print("Acquired on port 0 with " + str(rate_counter.rate) + " fps")
49print("Overall measurement time: " +str(duration / 1000) + " seconds")
50
51
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:1629
Frame rate measurement counter with selectable averaging window.
Definition: __init__.py:5091
Speed measurement object.
Definition: __init__.py:5698
str install_path()
Directory Common Vision Blox has been installed to.
Definition: __init__.py:8318