aboutsummaryrefslogtreecommitdiff
path: root/examples/camera/display_frame.py
diff options
context:
space:
mode:
authormorefigs <morefigs@gmail.com>2019-03-08 12:38:28 +1100
committermorefigs <morefigs@gmail.com>2019-03-08 12:38:28 +1100
commitbf764e872a4e4abea8d28e4c49b88b64f0bcdaaf (patch)
treeed218d638eb76e2b0cc19d27d3df676f7551c0ea /examples/camera/display_frame.py
parenta6bd629cfe0d143c5a159d496fd2e617a590f1e4 (diff)
downloadpymba-bf764e872a4e4abea8d28e4c49b88b64f0bcdaaf.tar.gz
pymba-bf764e872a4e4abea8d28e4c49b88b64f0bcdaaf.zip
Only show 1 image in loop
Diffstat (limited to 'examples/camera/display_frame.py')
-rw-r--r--examples/camera/display_frame.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/camera/display_frame.py b/examples/camera/display_frame.py
new file mode 100644
index 0000000..d0849c9
--- /dev/null
+++ b/examples/camera/display_frame.py
@@ -0,0 +1,33 @@
+from typing import Optional
+import cv2
+from pymba import Frame
+
+
+# todo add more colours
+PIXEL_FORMAT_MAPPING = {
+ 'BayerRG8': cv2.COLOR_BAYER_RG2RGB,
+}
+
+
+def display_frame(frame: Frame, delay: Optional[int] = 1) -> None:
+ """
+ Processes the acquired frame.
+ :param frame: The frame object to process.
+ :param delay: Image display delay in milliseconds, use 0 for indefinite.
+ """
+ print(f'frame {frame.data.frameID}')
+
+ # get a copy of the frame data
+ image = frame.buffer_data_numpy()
+
+ # convert colour space if desired
+ try:
+ image = cv2.cvtColor(image, PIXEL_FORMAT_MAPPING[frame.pixel_format])
+ except KeyError:
+ pass
+
+ # display image
+ cv2.imshow('Image', image)
+
+ # wait for user to close window
+ cv2.waitKey(delay)