aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormorefigs <morefigs@gmail.com>2019-02-09 15:57:44 +1100
committermorefigs <morefigs@gmail.com>2019-02-09 15:57:44 +1100
commitec95851f68d24e4201d4698a2657d90a174c05fa (patch)
treea4261d030aa8383b93b9c6ba7fafa305e85c5c15
parente9a094cadc47d8b4ba3ffbc80e64f17decdbc32b (diff)
downloadpymba-ec95851f68d24e4201d4698a2657d90a174c05fa.tar.gz
pymba-ec95851f68d24e4201d4698a2657d90a174c05fa.zip
refactor to clean up buffer access functions
-rw-r--r--examples/camera/opencv_capture_image.py2
-rw-r--r--examples/camera/opencv_capture_image_with_callback.py2
-rw-r--r--pymba/frame.py22
3 files changed, 12 insertions, 14 deletions
diff --git a/examples/camera/opencv_capture_image.py b/examples/camera/opencv_capture_image.py
index cf5305f..c185f6d 100644
--- a/examples/camera/opencv_capture_image.py
+++ b/examples/camera/opencv_capture_image.py
@@ -19,7 +19,7 @@ if __name__ == '__main__':
camera.run_feature_command('AcquisitionStop')
# get the image data as a numpy array
- image = frame.image_numpy_array()
+ image = frame.buffer_data_numpy()
# display image
cv2.imshow(camera.camera_id, image)
diff --git a/examples/camera/opencv_capture_image_with_callback.py b/examples/camera/opencv_capture_image_with_callback.py
index b7bc7ff..67cabdf 100644
--- a/examples/camera/opencv_capture_image_with_callback.py
+++ b/examples/camera/opencv_capture_image_with_callback.py
@@ -8,7 +8,7 @@ def on_callback(completed_frame: Frame):
print('Callback called!')
# get the image data as a numpy array
- image = completed_frame.image_numpy_array()
+ image = completed_frame.buffer_data_numpy()
# display image
cv2.imshow(camera.camera_id, image)
diff --git a/pymba/frame.py b/pymba/frame.py
index ef3ec53..7a4bb3b 100644
--- a/pymba/frame.py
+++ b/pymba/frame.py
@@ -108,24 +108,22 @@ class Frame:
if error:
raise VimbaException(error)
- def image_pointer(self):
+ def buffer_data(self):
"""
- Get a pointer to the frame's image data as a ctypes c_ubyte array pointer.
+ Get a copy of the frame's buffer data as a ctypes c_ubyte array.
"""
- return cast(self._vmb_frame.buffer, POINTER(c_ubyte * self._vmb_frame.bufferSize))
+ # create a ctypes pointer to the buffer
+ buffer_ptr = cast(self.data.buffer, POINTER(c_ubyte * self.data.bufferSize))
- def image_buffer(self):
- """
- Get a copy of the frame's image data as a ctypes c_ubyte array.
- """
- return self.image_pointer().contents
+ # contents always returns a copy
+ return buffer_ptr.contents
- def image_numpy_array(self) -> np.ndarray:
+ def buffer_data_numpy(self) -> np.ndarray:
"""
- Get the frame's image data as a NumPy array, which can be used with OpenCV.
+ Get a copy of the frame's buffer data as a NumPy array. This can easily be used with OpenCV.
"""
# todo pixel formats larger than 8-bit
- return np.ndarray(buffer=self.image_buffer(),
+ return np.ndarray(buffer=self.buffer_data(),
dtype=np.uint8,
- shape=(self._vmb_frame.height, self._vmb_frame.width))
+ shape=(self.data.height, self.data.width))