前言
接上面的功能完成之后,接下来就要完成触发采图了,这个触发采图耗费的时间比上面那个要长多了,主要原因还是在于对使用的函数理解不够深刻,后面听我细细道来。
首先,我们最主要使用的是这个回调函数,
MdigHookFunction(MilDigitizer, M_GRAB_FRAME_START, ProcessingFunction, &UserHookData);
MdigControl( MilDigitizer, M_GRAB_TRIGGER, M_ENABLE);
MdigControl( MilDigitizer, M_GRAB_TRIGGER_SOURCE, M_SOFTWARE);
这个函数会在程序有采图操作的时候并且有触发操作时执行ProcessingFunction这个函数。采图函数的话,我们使用的是MdigContinuous,这个采图函数可以进行连续采图,不过,它也有它比较独特的特点,具体看这篇文章,它的特点是MdigGrabContinuous为异步采集模式,在采集过程中是直接送到显存中的,不保存在MilBufferImage中,只有停止采集后的最后一帧保存在MilBufferImage中,一般用于实现在线观测功能,要想实现实时抓取图像和处理只能采用MdigGrab和MdigProcess函数。
效果图
因为这里的相机没有加光源和镜头,所以整体的效果看起来就是这样。
正文
打开回调采图模式
首先,我们要先打开回调采图模式。也就是上面的打开TriggerMode
的这个操作,这个操作执行了下面的这个函数:
GrabThreadStart
qint32 MDeviceE2v::GrabThreadStart()
{
qint32 ret = RETURN_FAIL;
#ifdef WIN32_E2v
MIL_INT WidthVal = 0;
//下面的这个语句是获得相机参数的语句,但是对于CL接口的相机是不能使用的,CXP接口的才能使用
//MdigInquireFeature(MilDigitizer, M_FEATURE_VALUE, MIL_TEXT("Width"), M_TYPE_INT64, &WidthVal);
// MdigControl(MilDigitizer, M_GRAB_TRIGGER_SOURCE, M_SOFTWARE);
// MdigControl(MilDigitizer, M_GRAB_TRIGGER_STATE, M_ENABLE);
MdigGrabContinuous(MilDigitizer, MilImage);
MdigHookFunction(MilDigitizer, M_GRAB_FRAME_END, ProcessingFunction, &UserHookData);
MdigControl( MilDigitizer, M_GRAB_TRIGGER, M_ENABLE );
MdigControl( MilDigitizer, M_GRAB_TRIGGER_SOURCE, M_SOFTWARE);
MdigControl( MilDigitizer, M_GRAB_MODE, M_ASYNCHRONOUS );
MIL_INT GrabContinuousEndTrigger = 0;
// MIL_INT GrabTriggerActivation = 0;
// MIL_INT GrabTriggerSource = 0;
// MIL_INT GrabTriggerState = 0;
MdigInquire(MilDigitizer, M_GRAB_CONTINUOUS_END_TRIGGER, &GrabContinuousEndTrigger);
// MdigInquire(MilDigitizer, M_GRAB_TRIGGER_ACTIVATION, &GrabTriggerActivation);
// MdigInquire(MilDigitizer, M_GRAB_TRIGGER_SOURCE, &GrabTriggerSource);
// MdigInquire(MilDigitizer, M_GRAB_TRIGGER_STATE, &GrabTriggerState);
qDebug()<<"GrabContinuous is"<<GrabContinuousEndTrigger;
if (GrabContinuousEndTrigger == M_DEFAULT) // Specifies the default value.
{
qDebug()<<"GrabContinuousEndTrigger is M_DEFAULT";
}
else if (GrabContinuousEndTrigger == M_DISABLE) // Specifies not to generate the trigger automatically.
{
qDebug()<<"GrabContinuousEndTrigger is M_DISABLE";
}
else if (GrabContinuousEndTrigger == M_ENABLE) // Specifies to generate the trigger automatically.
{
qDebug()<<"GrabContinuousEndTrigger is M_ENABLE";
}
MIL_INT AllocationOverscan = 0;
MsysInquire(MilSystem, M_ALLOCATION_OVERSCAN, &AllocationOverscan);
if (AllocationOverscan == M_DEFAULT)