diff options
| author | John Sun <jsun@sightmachine.com> | 2014-04-02 16:22:14 -0700 |
|---|---|---|
| committer | John Sun <jsun@sightmachine.com> | 2014-04-02 16:22:14 -0700 |
| commit | 01e24424971ffa9faa5dabf2e6724cea997a2afb (patch) | |
| tree | 8882d0e2c93e2a1f74178c21b6bffa02a2edee16 /pyvimba/vimbaframe.py | |
| parent | 54bec3f39dc7915593a29c22ed1aac0e29ab53b6 (diff) | |
| download | pymba-01e24424971ffa9faa5dabf2e6724cea997a2afb.tar.gz pymba-01e24424971ffa9faa5dabf2e6724cea997a2afb.zip | |
First pass at making pymba a pip installable module.
1) Moved all the source-code under a new folder "pyvimba". Yes I changed the name. Feel free to change it back
2) Added initial CHANGES.txt, MANIFEST.in, LICENSE, README.txt
3) Move opencv_example.py to "tests" directory
Diffstat (limited to 'pyvimba/vimbaframe.py')
| -rw-r--r-- | pyvimba/vimbaframe.py | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/pyvimba/vimbaframe.py b/pyvimba/vimbaframe.py new file mode 100644 index 0000000..e97360e --- /dev/null +++ b/pyvimba/vimbaframe.py @@ -0,0 +1,89 @@ +# -*- coding: utf-8 -*- +import vimbastructure as structs +from vimbaexception import VimbaException +from vimbadll import VimbaDLL +from vimbadll import VimbaC_MemoryBlock +from ctypes import * + +class VimbaFrame(object): + """ + A Vimba frame. + """ + 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 + + # frame structure + self._frame = structs.VimbaFrame() + + def announceFrame(self): + """ + Announce frames to the API that may be queued for frame capturing later. + """ + # 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. + """ + errorCode = VimbaDLL.captureFrameQueue(self._handle, + byref(self._frame), + 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). + """ + errorCode = VimbaDLL.captureFrameWait(self._handle, + byref(self._frame), + timeout) + if errorCode != 0: + raise VimbaException(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)) + + return array |
