Skip to content

Commit

Permalink
Added versioneer and updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbaker committed Mar 24, 2022
1 parent d405ea7 commit af8f0a1
Show file tree
Hide file tree
Showing 13 changed files with 2,865 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin/* binary
bin/* binary
pymagewell/_version.py export-subst
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include versioneer.py
include pymagewell/_version.py
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# pymagewell
Python library for interfacing with Magewell ProCapture frame grabbers

### Example of use
First, create a `ProCaptureSettings` dataclass:
```python
from pymagewell.pro_capture_device.device_settings import (
ProCaptureSettings, ImageSizeInPixels, TransferMode, ColourFormat
)

device_settings = ProCaptureSettings(
dimensions=ImageSizeInPixels(1920, 1080),
color_format=ColourFormat.BGR24, # Color format of captured video frames
transfer_mode = TransferMode.LOW_LATENCY,
num_lines_per_chunk = 64 # has effect only in low latency mode
)
```
Then create a `ProCaptureDevice` (or `MockProCaptureDevice` for testing on a system without a grabber) configured with
your chosen settings:
```python
from pymagewell.pro_capture_device import ProCaptureDevice

device = ProCaptureDevice(settings=device_settings)
```
Then create a `ProCaptureDeviceController` to transfer frames from the device to your PC:
```python
from pymagewell.pro_capture_controller import ProCaptureController

controller = ProCaptureController(device)
```
Then you can grab frames in a loop using the `transfer_when_ready()` method, which will wait until a frame has been
acquired by the device, transfer it from the device to the PC, and return it as a `VideoFrame` object.
```python
while True:
frame = controller.transfer_when_ready()
```
`VideoFrame` provides access to the pixels as Pillow image with its `as_pillow_image()` method, or a Numpy array with
its `as_numpy_array` method. It also provides access to a Timestamp generated when the frame was ready for transfer from
the card to the PC.
10 changes: 6 additions & 4 deletions capture_script.py → example_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from cv2 import imshow, waitKey
from numpy import array, diff

import versioneer
from pymagewell.pro_capture_device import ProCaptureDevice
from pymagewell.pro_capture_controller import ProCaptureController
from pymagewell.pro_capture_device.device_settings import ProCaptureSettings, TransferMode
Expand All @@ -15,21 +16,22 @@
device_settings = ProCaptureSettings()
device_settings.transfer_mode = TransferMode.LOW_LATENCY
device = ProCaptureDevice(device_settings)
frame_grabber = ProCaptureController(device)
controller = ProCaptureController(device)

print(f'pymagewell version {versioneer.get_version()}')
print('PRESS Q TO QUIT!')

counter = 0
timestamps = []
while True:
frame = frame_grabber.transfer_when_ready()
frame = controller.transfer_when_ready()
timestamps.append(frame.timestamp)
imshow("video", frame.as_array())
if waitKey(1) & 0xFF == ord('q'):
break
if counter % 20 == 0:
if counter % 20 == 19:
mean_period = array([p.total_seconds() for p in diff(array(timestamps))]).mean()
print(f'Average frame rate over last 20 frames: {1 / mean_period} Hz')
print(f'Last frame timestamp: {frame.timestamp}')
counter += 1
frame_grabber.shutdown()
controller.shutdown()
1 change: 1 addition & 0 deletions mwcapture/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""" These files were provided by Magewell as part of the Windows SDK. """
3 changes: 3 additions & 0 deletions pymagewell/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import _version

__version__ = _version.get_versions()["version"] # type: ignore
Loading

0 comments on commit af8f0a1

Please sign in to comment.