diff options
| author | morefigs <morefigs@gmail.com> | 2014-08-04 13:22:31 +1000 |
|---|---|---|
| committer | morefigs <morefigs@gmail.com> | 2014-08-04 13:22:31 +1000 |
| commit | f672513907c134db2794519fe79f5a4e1f8d6a44 (patch) | |
| tree | cabfbaba9957fc16ee36e0d095864a54c58c0e01 | |
| parent | 4ce1ba30cfcc8d53adea400e476fc2c513da7106 (diff) | |
| parent | 51b885759ea258362de649be28af16a5fec9b35f (diff) | |
| download | pymba-f672513907c134db2794519fe79f5a4e1f8d6a44.tar.gz pymba-f672513907c134db2794519fe79f5a4e1f8d6a44.zip | |
Merge pull request #5 from derricw/master
Support for other pixel formats.
| -rw-r--r-- | pymba/tests/opencv_liveview_example.py | 7 | ||||
| -rw-r--r-- | pymba/vimba.py | 4 | ||||
| -rw-r--r-- | pymba/vimbaframe.py | 74 |
3 files changed, 50 insertions, 35 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/vimba.py b/pymba/vimba.py index 678e7b0..ffb3a91 100644 --- a/pymba/vimba.py +++ b/pymba/vimba.py @@ -173,7 +173,7 @@ class Vimba(object): :param interfaceId: the ID of the interface. - :returns: VimbaInterface object -- the interface object specified. + :returns: VimbaInterface object -- the interface object specified. """ # check ID is valid if interfaceId in self.getInterfaceIds(): @@ -190,7 +190,7 @@ class Vimba(object): :param cameraId: the ID of the camera. - :returns: VimbaCamera object -- the camera object specified. + :returns: VimbaCamera object -- the camera object specified. """ # check ID is valid if cameraId in self.getCameraIds(): diff --git a/pymba/vimbaframe.py b/pymba/vimbaframe.py index c65f160..9e92285 100644 --- a/pymba/vimbaframe.py +++ b/pymba/vimbaframe.py @@ -5,6 +5,17 @@ from vimbadll import VimbaDLL from vimbadll import VimbaC_MemoryBlock from ctypes import * +#map pixel formats to bytes per pixel. TODO: packed mono formats? +PIXEL_FORMATS = { + "Mono8": 1, + "Mono12": 2, + "Mono14": 2, + "Mono16": 2, + "RGB8Packed": 3, + "BGR8Packed": 3, +} + + class VimbaFrame(object): """ A Vimba frame. @@ -12,100 +23,101 @@ 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. - + Runs VmbFrameAnnounce - - Should be called after the frame is created. Call startCapture + + Should be called after the frame is created. Call startCapture after this method. - """ + """ # size of expected frame sizeOfFrame = self.payloadSize - + # keep this reference to keep block alive for life of frame self._cMem = VimbaC_MemoryBlock(sizeOfFrame) # set buffer to have length of expected payload size self._frame.buffer = self._cMem.block - + # set buffer size to expected payload size self._frame.bufferSize = sizeOfFrame - + errorCode = VimbaDLL.frameAnnounce(self._handle, byref(self._frame), sizeof(self._frame)) - + if errorCode != 0: raise VimbaException(errorCode) - + def revokeFrame(self): """ Revoke a frame from the API. """ errorCode = VimbaDLL.frameRevoke(self._handle, byref(self._frame)) - + if errorCode != 0: raise VimbaException(errorCode) - + def queueFrameCapture(self): """ Queue frames that may be filled during frame capturing. Runs VmbCaptureFrameQueue - + Call after announceFrame and startCapture """ errorCode = VimbaDLL.captureFrameQueue(self._handle, byref(self._frame), - None) # callback not implemented, callback example in pico? + None) # callback not implemented, callback example in pico? 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. Runs VmbCaptureFrameWait - - timeout - int, milliseconds default(timeout, 2000) - + + timeout - int, milliseconds default(timeout, 2000) + Call after an acquisition command """ errorCode = VimbaDLL.captureFrameWait(self._handle, byref(self._frame), timeout) - + # errorCode to be processed by the end user for this function. # 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 |
