diff options
| author | Derric Williams <derricw@alleninstitute.org> | 2014-07-08 09:30:39 -0700 |
|---|---|---|
| committer | Derric Williams <derricw@alleninstitute.org> | 2014-07-08 09:30:39 -0700 |
| commit | ec7e44c7f2820962cd3942b6a59d32fd58b7d5ed (patch) | |
| tree | 24d8b99a80df7df85527fad05a31dc8183f72dc3 | |
| parent | 7d46e407f84245dc495ba1c477a331d8c1537ea8 (diff) | |
| download | pymba-ec7e44c7f2820962cd3942b6a59d32fd58b7d5ed.tar.gz pymba-ec7e44c7f2820962cd3942b6a59d32fd58b7d5ed.zip | |
VimbaFrame now supports unpacked pixel formats: Mono12, Mono16
| -rw-r--r-- | pymba/tests/opencv_liveview_example.py | 7 | ||||
| -rw-r--r-- | pymba/vimbaframe.py | 33 |
2 files changed, 26 insertions, 14 deletions
diff --git a/pymba/tests/opencv_liveview_example.py b/pymba/tests/opencv_liveview_example.py index 83331ac..1382d82 100644 --- a/pymba/tests/opencv_liveview_example.py +++ b/pymba/tests/opencv_liveview_example.py @@ -37,6 +37,9 @@ except: #not a gigE camera pass +#set pixel format +c0.PixelFormat="Mono8" + frame = c0.getFrame() frame.announceFrame() @@ -46,7 +49,6 @@ framecount = 0 droppedframes = [] while 1: - print framecount try: frame.queueFrameCapture() success = True @@ -56,8 +58,9 @@ while 1: c0.runFeatureCommand("AcquisitionStart") c0.runFeatureCommand("AcquisitionStop") frame.waitFrameCapture(100) + frame_data = frame.getBufferByteData() if success: - img = np.ndarray(buffer=frame.getBufferByteData(), + img = np.ndarray(buffer=frame_data, dtype=np.uint8, shape=(frame.height,frame.width,1)) cv2.imshow("test",img) diff --git a/pymba/vimbaframe.py b/pymba/vimbaframe.py index c65f160..9e2a22d 100644 --- a/pymba/vimbaframe.py +++ b/pymba/vimbaframe.py @@ -5,6 +5,14 @@ from vimbadll import VimbaDLL from vimbadll import VimbaC_MemoryBlock from ctypes import * +#map formats to bytes per pixel +PIXEL_FORMATS = { + "Mono8": 1, + "Mono12": 2, + "Mono16": 2, +} + + class VimbaFrame(object): """ A Vimba frame. @@ -12,15 +20,16 @@ class VimbaFrame(object): def __init__(self, camera): self._camera = camera self._handle = camera.handle - + # get frame sizes self.payloadSize = self._camera.PayloadSize self.width = self._camera.Width self.height = self._camera.Height - + self.pixel_bytes = PIXEL_FORMATS[self._camera.PixelFormat] + # frame structure self._frame = structs.VimbaFrame() - + def announceFrame(self): """ Announce frames to the API that may be queued for frame capturing later. @@ -71,7 +80,7 @@ class VimbaFrame(object): if errorCode != 0: raise VimbaException(errorCode) - def waitFrameCapture(self, timeout = 2000): + def waitFrameCapture(self, timeout=2000): """ Wait for a queued frame to be filled (or dequeued). Returns Errorcode upon completion. @@ -89,23 +98,23 @@ class VimbaFrame(object): # Prevents system for breaking for example on a hardware trigger # timeout #if errorCode != 0: - #raise VimbaException(errorCode) + #raise VimbaException(errorCode) return errorCode # custom method for simplified usage def getBufferByteData(self): """ Retrieve buffer data in a useful format. - + :returns: array -- buffer data. """ - + # cast frame buffer memory contents to a usable type data = cast(self._frame.buffer, POINTER(c_ubyte * self.payloadSize)) - - # make array of c_ubytes from buffer - - array = (c_ubyte * self.height * self.width).from_address(addressof(data.contents)) - + + # make array of c_ubytes from buffer + array = (c_ubyte * (self.height*self.pixel_bytes) * + (self.width*self.pixel_bytes)).from_address(addressof(data.contents)) + return array |
