Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hardware trigger support #655

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
64 changes: 43 additions & 21 deletions SimpleCV/Camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2720,7 +2720,6 @@ class AVTCamera(FrameSource):
>>> img = cam.getImage()
>>> img.show()
"""


_buffer = None # Buffer to store images
_buffersize = 10 # Number of images to keep in the rolling image buffer for threads
Expand Down Expand Up @@ -2965,7 +2964,6 @@ def __init__(self, camera_id = -1, properties = {}, threaded = False):
#call, since it blocks on cameras initializing

camlist = self.listAllCameras()

if not len(camlist):
raise Exception("Couldn't find any cameras with the PvAVT driver. Use SampleViewer to confirm you have one connected.")

Expand All @@ -2976,6 +2974,7 @@ def __init__(self, camera_id = -1, properties = {}, threaded = False):
camera_id = camlist[camera_id].UniqueId

camera_id = long(camera_id)

self.handle = ct.c_uint()
init_count = 0
while self.dll.PvCameraOpen(camera_id,0,ct.byref(self.handle)) != 0: #wait until camera is availble
Expand Down Expand Up @@ -3189,7 +3188,7 @@ def setProperty(self, name, value, skip_buffer_size_check=False):

return err

def getImage(self, timeout = 5000):
def getImage(self, timeout = 5000, hwtrigger = False):
"""
**SUMMARY**
Extract an Image from the Camera, returning the value. No matter
Expand All @@ -3201,7 +3200,7 @@ def getImage(self, timeout = 5000):
>>>c = AVTCamera()
>>>c.getImage().show()
"""

if self.frame != None:
st = time.time()
try:
Expand All @@ -3224,12 +3223,16 @@ def getImage(self, timeout = 5000):
self._thread.lock.release()

else:

self.runCommand("AcquisitionStart")
frame = self._getFrame(timeout)
frame = self._getFrame(timeout,hwtrigger)

img = Image(pil.fromstring(self.imgformat,
(self.width, self.height),
frame.ImageBuffer[:int(frame.ImageBufferSize)]))
self.runCommand("AcquisitionStop")


return img


Expand Down Expand Up @@ -3258,24 +3261,43 @@ def _refreshFrameStats(self):
if self.pixelformat == 'Mono8':
self.imgformat = 'L'

def _getFrame(self, timeout = 5000):
def _getFrame(self, timeout = 5000, hwtrigger = False):
#return the AVTFrame object from the camera, timeout in ms
#need to multiply by bitdepth
try:
frame = self.AVTFrame(self.buffersize)
pverr( self.dll.PvCaptureQueueFrame(self.handle, ct.byref(frame), None) )
st = time.time()
try:
pverr( self.dll.PvCaptureWaitForFrameDone(self.handle, ct.byref(frame), timeout) )
except Exception, e:
print "Exception waiting for frame:", e
print "Time taken:",time.time() - st
raise(e)

except Exception, e:
print "Exception aquiring frame:", e
raise(e)


if hwtrigger == False:
try:
frame = self.AVTFrame(self.buffersize)
pverr( self.dll.PvCaptureQueueFrame(self.handle, ct.byref(frame), None) )
st = time.time()
try:
pverr( self.dll.PvCaptureWaitForFrameDone(self.handle, ct.byref(frame), timeout) )
except Exception, e:
print "Exception waiting for frame:", e
print "Time taken:",time.time() - st
raise(e)

except Exception, e:
print "Exception aquiring frame:", e
raise(e)
else:
try:
frame = self.AVTFrame(self.buffersize)
pverr( self.dll.PvCaptureQueueFrame(self.handle, ct.byref(frame), None) )
st = time.time()
try:
while self.dll.PvCaptureWaitForFrameDone(self.handle, ct.byref(frame), timeout) == 17: #timeout error
print ("waiting trigger")

except Exception, e:
print "Exception waiting for frame:", e
print "Time taken:",time.time() - st
raise(e)

except Exception, e:
print "Exception aquiring frame:", e
raise(e)

return frame

def acquire(self):
Expand Down