aboutsummaryrefslogtreecommitdiff
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
parenta6bd629cfe0d143c5a159d496fd2e617a590f1e4 (diff)
downloadpymba-bf764e872a4e4abea8d28e4c49b88b64f0bcdaaf.tar.gz
pymba-bf764e872a4e4abea8d28e4c49b88b64f0bcdaaf.zip
Only show 1 image in loop
-rw-r--r--examples/camera/display_frame.py33
-rw-r--r--examples/camera/opencv_acquire_image.py24
-rw-r--r--examples/camera/opencv_acquire_streaming_images.py22
-rw-r--r--pymba/frame.py1
4 files changed, 41 insertions, 39 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)
diff --git a/examples/camera/opencv_acquire_image.py b/examples/camera/opencv_acquire_image.py
index 8925961..741f449 100644
--- a/examples/camera/opencv_acquire_image.py
+++ b/examples/camera/opencv_acquire_image.py
@@ -1,21 +1,5 @@
-import cv2
-from pymba import Vimba, Frame
-
-
-def process_frame(frame: Frame):
- """
- Processes the acquired frame.
- """
- print(f'frame {frame.data.frameID} callback')
-
- # get a copy of the frame data
- image = frame.buffer_data_numpy()
-
- # display image
- cv2.imshow('Image', image)
-
- # wait for user to close window
- cv2.waitKey(0)
+from pymba import Vimba
+from examples.camera.display_frame import display_frame
if __name__ == '__main__':
@@ -28,8 +12,8 @@ if __name__ == '__main__':
# capture a single frame, more than once if desired
for i in range(1):
- frame_ = camera.acquire_frame()
- process_frame(frame_)
+ frame = camera.acquire_frame()
+ display_frame(frame, 0)
camera.disarm()
diff --git a/examples/camera/opencv_acquire_streaming_images.py b/examples/camera/opencv_acquire_streaming_images.py
index e813672..3dfe3da 100644
--- a/examples/camera/opencv_acquire_streaming_images.py
+++ b/examples/camera/opencv_acquire_streaming_images.py
@@ -1,22 +1,6 @@
from time import sleep
-import cv2
-from pymba import Vimba, Frame
-
-
-def process_frame(frame: Frame):
- """
- Process the streaming frames. Consider sending the frame data to another thread/process if this is long running to
- avoid dropping frames.
- """
- print(f'frame {frame.data.frameID} callback')
-
- # get a copy of the frame data
- image = frame.buffer_data_numpy()
-
- # display image
- # note that this function is called in a thread, and therefore cv2 windows must be destroyed by the same thread
- cv2.imshow('Image', image)
- cv2.waitKey(1)
+from pymba import Vimba
+from examples.camera.display_frame import display_frame
if __name__ == '__main__':
@@ -26,7 +10,7 @@ if __name__ == '__main__':
camera.open()
# arm the camera and provide a function to be called upon frame ready
- camera.arm('Continuous', process_frame)
+ camera.arm('Continuous', display_frame)
camera.start_frame_acquisition()
# stream images for a while...
diff --git a/pymba/frame.py b/pymba/frame.py
index b7803aa..871d22d 100644
--- a/pymba/frame.py
+++ b/pymba/frame.py
@@ -14,6 +14,7 @@ class Frame:
def __init__(self, camera: '_camera.Camera'):
self._camera = camera
+ self.pixel_format = self._camera.PixelFormat
self._vmb_frame = vimba_c.VmbFrame()