From ec7e44c7f2820962cd3942b6a59d32fd58b7d5ed Mon Sep 17 00:00:00 2001 From: Derric Williams Date: Tue, 8 Jul 2014 09:30:39 -0700 Subject: VimbaFrame now supports unpacked pixel formats: Mono12, Mono16 --- pymba/tests/opencv_liveview_example.py | 7 +++++-- 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 -- cgit v1.2.3 From f5b5cd23c31f7e60af168df86c4ac71fc1ea66a1 Mon Sep 17 00:00:00 2001 From: Derric Williams Date: Fri, 11 Jul 2014 14:28:21 -0700 Subject: Support for Mono14 PixelFormat --- pymba/vimba.py | 4 ++-- pymba/vimbaframe.py | 41 +++++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 22 deletions(-) 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 9e2a22d..b01dc2a 100644 --- a/pymba/vimbaframe.py +++ b/pymba/vimbaframe.py @@ -5,10 +5,11 @@ from vimbadll import VimbaDLL from vimbadll import VimbaC_MemoryBlock from ctypes import * -#map formats to bytes per pixel +#map formats to bytes per pixel. TODO: packed formats? color? PIXEL_FORMATS = { "Mono8": 1, "Mono12": 2, + "Mono14": 2, "Mono16": 2, } @@ -33,74 +34,74 @@ class VimbaFrame(object): 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): """ 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) return errorCode - + # custom method for simplified usage def getBufferByteData(self): """ -- cgit v1.2.3 From 51b885759ea258362de649be28af16a5fec9b35f Mon Sep 17 00:00:00 2001 From: Derric Williams Date: Fri, 1 Aug 2014 18:44:43 -0700 Subject: RGB8 support --- pymba/vimbaframe.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pymba/vimbaframe.py b/pymba/vimbaframe.py index b01dc2a..9e92285 100644 --- a/pymba/vimbaframe.py +++ b/pymba/vimbaframe.py @@ -5,12 +5,14 @@ from vimbadll import VimbaDLL from vimbadll import VimbaC_MemoryBlock from ctypes import * -#map formats to bytes per pixel. TODO: packed formats? color? +#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, } -- cgit v1.2.3