CVBpy 15.0
All Classes Namespaces Functions Variables Enumerations Enumerator Properties Modules Pages
cvb/StreamingAsync
1# @brief Example for asynchronous streaming.
2
3# CVBpy Example Script
4#
5# 1. Open the CVMock.vin driver.
6# 2. Asynchronously acquire images.
7# 3. Measure the frame rate and print results.
8#
9# Note: can be extended to multible cameras.
10
11
12import os
13import asyncio
14import cvb
15
16
17
18
19rate_counter = None
20
21async def async_acquire(port):
22 global rate_counter
23 with cvb.DeviceFactory.open(os.path.join(cvb.install_path(), "drivers", "CVMock.vin"), port=port) as device:
24 stream = device.stream()
25 stream.start()
26
27 rate_counter = cvb.RateCounter()
28
29 for i in range(0, 100):
30 result = await stream.wait_async()
31 image, status = result.value
32 rate_counter.step()
33 if status == cvb.WaitStatus.Ok:
34 print("Buffer index: " + str(image.buffer_index) + " from stream: " + str(port))
35
36 stream.abort()
37
38
39
40
41watch = cvb.StopWatch()
42
43loop = asyncio.get_event_loop()
44loop.run_until_complete(asyncio.gather(
45 async_acquire(port=0)))
46loop.close()
47
48duration = watch.time_span
49
50print("Acquired on port 0 with " + str(rate_counter.rate) + " fps")
51print("Overall measurement time: " +str(duration / 1000) + " seconds")
52
53
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