morefigs / pymba

Python wrapper for Allied Vision's Vimba C API
MIT License
105 stars 84 forks source link

hardware trigger #39

Closed ypark137 closed 8 years ago

ypark137 commented 8 years ago

Hi, I have been having problems with Line 2 trigger. Line 2 trigger is working well on Vimba Viewer 2.0, but it doesn't take the trigger when using pymba. A code that is similar to this one was working before but it stopped working. I've tried restarting the camera and reinstalling pymba and vimba, and tried another computer also....My camera is GS1380. The liveview examples that comes with pymba are all working well.

from pymba import *
import cv2
import numpy as np

vimba = Vimba()

vimba.startup()

system = vimba.getSystem()
system.runFeatureCommand("GeVDiscoveryAllOnce")

cameraIds = vimba.getCameraIds()

camera = vimba.getCamera(cameraIds[0])

camera.openCamera()

camera.TriggerMode = 'On'
camera.TriggerSource = 'Line2'
camera.TriggerActivation = 'RisingEdge'
camera.PixelFormat = 'Mono8'
camera.TriggerSelector = 'FrameStart'
camera.AcquisitionMode = 'Continuous'

print 'TriggerMode:', camera.TriggerMode
print 'TriggerSource:', camera.TriggerSource
print 'TriggerActivation:', camera.TriggerActivation
print 'TriggerSelector:', camera.TriggerSelector

frame = camera.getFrame()

frame.announceFrame()

camera.startCapture()

frame.queueFrameCapture()

frame.waitFrameCapture(3000)

print 'frame 1 captured or timed out '

imgData1 = frame.getBufferByteData()

camera.endCapture()

data1_np = np.ndarray(buffer=imgData1,
                      dtype=np.uint8,
                      shape=(frame.height, frame.width))

rgb = cv2.cvtColor(data1_np, cv2.COLOR_BAYER_RG2RGB)

cv2.imwrite('testTrigger.png'.format(1), rgb)
camera.revokeAllFrames()
camera.closeCamera()
print 'frame is saved as png'
morefigs commented 8 years ago

Does adding camera.runFeatureCommand('AcquisitionStart') right after frame.queueFrameCapture() and camera.runFeatureCommand('AcquisitionStop') after frame.waitFrameCapture(3000) help?

ypark137 commented 8 years ago

It works! Thanks!

morefigs commented 8 years ago

Glad to hear it =)

lsgcv commented 4 years ago

Hi, since this was opened in 2016, can you provide an updated example? I noticed that the method names listed above have changed since 2016.

Thank you!