安装完驱动和相关文件后,相机有自带的SDK和编程手册。(一般是有一张光盘)
先说一下大致流程:
系统流程:
①系统列表:是否安装了对应的系统入口(Gige或USB)
打开一个系统
②获取系统中的接口列表(I/O接口:Gige接口或者USB接口)
打开接口
③获取连接在接口上的设备列表
打开设备->需要打开相机的软触发模式
④获取从相机传入的数据流列表
打开数据流入口
⑤创建缓冲列表并分配缓冲内存
⑥为数据流分配接收的图像内存
⑦开启相机获取数据流并填充图像缓冲
⑧结束后释放资源
上代码:
/************************************************************************/
/*
系统流程:
①系统列表:是否安装了对应的系统入口(Gige或USB)
打开一个系统
②获取系统中的接口列表(I/O接口:Gige接口或者USB接口)
打开接口
③获取连接在接口上的设备列表
打开设备->需要打开相机的软触发模式
④获取从相机传入的数据流列表
打开数据流入口
⑤创建缓冲列表并分配缓冲内存
⑥为数据流分配接收的图像内存
⑦开启相机获取数据流并填充图像缓冲
⑧结束后释放资源
*/
/************************************************************************/
/*准备工作*/
#include
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include
#include
#include
#include "bgapi2_genicam/bgapi2_genicam.hpp"
using namespace BGAPI2;
using namespace std;
using namespace cv;
int main()
{
/************************************************************************
设置相机参数
************************************************************************/
/*系统列表和系统参数*/
SystemList* systemList = NULL;// 系统列表。有gige接口和usb接口两种系统。本机为gige系统。
System* pSystem = NULL;// 指向当前系统的指针
BGAPI2::String sSystemID;// 当前系统的ID号,字符串。
/*接口列表和接口参数*/
InterfaceList* interfaceList = NULL;// 接口列表,共一个接口:一个网口接口
Interface* pInterface = NULL;// 指向当前接口的指针
BGAPI2::String sInterfaceID;// 当前接口的ID号,字符串。
/*设备列表和设备参数*/
DeviceList* deviceList = NULL;// 设备列表,本机共一个设备(共一个接口)
Device* pDevice = NULL;// 指向当前设备的指针
BGAPI2::String sDeviceID;// 当前设备的ID号,字符串。
/*数据流列表和数据流参数*/
DataStreamList* datastreamList = NULL;// 数据流列表,共一个数据流
DataStream* pDataStream = NULL;// 指向当前数据流的指针
BGAPI2::String sDataStreamID;// 当前数据流的ID号,字符串。
/*缓冲列表和缓冲参数*/
BufferList* bufferList = NULL;// 缓冲列表,缓冲列表大小可设置
Buffer* pBuffer = NULL;// 指向当前缓冲的指针
/*图像处理参数*/
ImageProcessor * imgProcessor = NULL;
int returncode = 0;// 返回值
// 图像处理模块
try
{
imgProcessor = new ImageProcessor();
cout << "图像处理模块版本: " << imgProcessor->GetVersion() << endl;
if(imgProcessor->GetNodeList()->GetNodePresent("DemosaicingMethod") == true)
{
imgProcessor->GetNodeList()->GetNode("DemosaicingMethod")->SetString("NearestNeighbor"); // NearestNeighbor, Bilinear3x3, Baumer5x5
cout << " 差值方法: " << imgProcessor->GetNodeList()->GetNode("DemosaicingMethod")->GetString() << endl;
}
cout << endl;
}
catch(Exceptions::IException& ex)
{
cout << "异常类型:" << ex.GetType() << endl;
cout << "错误描述:" << ex.GetErrorDescription() << endl;
cout << "发生异常的功能:" << ex.GetFunctionName() << endl;
}
cout << "系统列表" << endl;
cout << "########" << endl << endl;
try// 获取系统列表,系统列表里包含了所有系统的信息
{
systemList = SystemList::GetInstance();// 实例化系统列表
systemList->Refresh();// 更新系统列表
cout<< "本机检测到的系统数:" << systemList->size() <begin(); sysIterator != systemList->end(); sysIterator++)// 在系统列表顶部传递迭代器
{
cout << "系统描述" << endl;
cout << "========" << endl;
cout << "系统名称:" << sysIterator->second->GetFileName() << endl;// 传递文件名
cout << "系统类型:" << sysIterator->second->GetTLType() << endl;// 类型
cout << "系统版本:" << sysIterator->second->GetVersion() << endl;// 版本
cout << "系统路径:" << sysIterator->second->GetPathName() << endl << endl;// 路径名
}// for循环结束
}
catch(Exceptions::IException& ex)
{
cout << "异常类型:" << ex.GetType() << endl;
cout << "错误描述:" << ex.GetErrorDescription() << endl;
cout << "发生异常的功能:" << ex.GetFunctionName() << endl;
}// 当前try-catch结束
// 在系统列表中搜索各个系统
try
{
for (SystemList::iterator sysIterator = systemList->begin();sysIterator != systemList->end();sysIterator++)// 所有的系统存放在一个迭代器中,搜索这个迭代器
{
cout << "对系统操作:" << endl;
cout << "**********" << endl << endl;
try
{
sysIterator->second->Open();// 包括所有的主要参数在内,都是以一对的形式存放(first,second),可理解为键值对,first为string键,second为指针类型的值
// Open函数打开系统对象并使其功能可用。即以下的功能。
// 指向当前系统的指针
cout << "打开当前系统" << endl;
cout << "------------" << endl << endl;
cout << " 系统名称:" << sysIterator->second->GetFileName() << endl;
cout << " 系统类型:" << sysIterator->second->GetTLType() << endl;
cout << " 系统版本:" << sysIterator->second->GetVersion() << endl;
cout << " 系统路径:" << sysIterator->second->GetPathName() << endl << endl;
sSystemID = sysIterator->first;// 获取系统的ID
cout << "已打开的系统----节点列表信息 " << endl;
cout << "GenTL版本:" << sysIterator->second->GetNode("GenTLVersionMajor")->GetValue() << "." << sysIterator->second->GetNode("GenTLVersionMinor")->GetValue() << endl << endl;
// (位于当前打开的系统中)在接口列表里搜索接口
cout << "接口列表" << endl;
cout << "########" << endl << endl;
try
{
interfaceList = sysIterator->second->GetInterfaces();// 通过当前系统的指针获取当前系统的接口列表
interfaceList->Refresh(100);// 更新接口列表每100毫秒
cout << "检测到的接口个数: " << interfaceList->size() << endl;
// 接口信息
for (InterfaceList::iterator ifIterator = interfaceList->begin();ifIterator != interfaceList->end();ifIterator++)
{
cout << "接口描述" << endl;
cout << "========" << endl;
cout << "接口 ID:" << ifIterator->first << endl;
cout << "接口类型:" << ifIterator->second->GetTLType() << endl;
cout << "接口名称:" << ifIterator->second->GetDisplayName() << endl << endl;
}// for循环结束
}
catch (Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型:" << ex.GetType() << endl;
cout << "错误描述:" << ex.GetErrorDescription() << endl;
cout << "发生异常的功能:" << ex.GetFunctionName() << endl;
}// try-catch结束 系统功能结束。
cout << "对接口操作" << endl;
cout << "**********" << endl << endl;
// 打开列表中的接口
try
{
for (InterfaceList::iterator ifIterator = interfaceList->begin(); ifIterator != interfaceList->end(); ifIterator++)
{
try
{
cout << "打开当前接口" << endl;
cout << "------------" << endl;
cout << "接口 ID:" << ifIterator->first << endl;
cout << "接口类型:" << ifIterator->second->GetTLType() << endl;
cout << "接口名称:" << ifIterator->second->GetDisplayName() << endl;
ifIterator->second->Open();
// 搜索所有连接到此接口的设备
deviceList = ifIterator->second->GetDevices();// 获取设备
deviceList->Refresh(100);
if(deviceList->size() == 0)// 没有搜索到设备
{
cout << "关闭接口 (发现" << deviceList->size() << " 个相机) " << endl << endl;
ifIterator->second->Close();// 此函数关闭接口对象并释放使用的资源。
}
else
{
sInterfaceID = ifIterator->first;// 获取接口名称
cout << "打开的接口 - 节点列表信息 " << std::endl;
if( ifIterator->second->GetTLType() == "GEV" )// 如果接口通过网口连接
{
// 接口子网IP地址
cout << "接口子网IP地址:" << ifIterator->second->GetNode("GevInterfaceSubnetIPAddress")->GetValue() << endl;
// 接口子网掩码
cout << "接口子网掩码:" << ifIterator->second->GetNode("GevInterfaceSubnetMask")->GetValue() << endl;
}
cout << " " << endl;
break;
}
}
catch (Exceptions::ResourceInUseException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << " 接口 " << ifIterator->first << " 已经被打开 " << endl;
cout << " 资源占用异常:" << ex.GetErrorDescription() << endl;
}// try-catch 结束,接口功能结束
}// for循环结束
}
catch (Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型: " << ex.GetType() << endl;
cout << "异常描述: " << ex.GetErrorDescription() << endl;
cout << "发生异常的功能: " << ex.GetFunctionName() << endl;
}
if(sInterfaceID != "") // 如果接口存在
{
break;
}
}
catch (Exceptions::ResourceInUseException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << " 系统 " << sysIterator->first << " 已经被打开 " << endl;
cout << " 资源占用异常: " << ex.GetErrorDescription() << endl;
}
}
}
catch (Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型:" << ex.GetType() << endl;
cout << "异常描述:" << ex.GetErrorDescription() << endl;
cout << "发生异常的功能:" << ex.GetFunctionName() << endl;
}
// 检查系统是否存在。
if ( sSystemID == "" )// 系统列表为空
{
cout << " 没有发现可用系统 " << endl;
cout << endl << "结束!" << endl << "按任意键来结束程序:";
int endKey = 0;
cin >> endKey;// 输入任意的按键值
SystemList::ReleaseInstance();// 释放实例资源
return returncode;// 返回0,退出函数
}
else
{
pSystem = (*systemList)[sSystemID];// 获取系统名称
}
// 检查接口是否存在。
if (sInterfaceID == "")// 接口不存在
{
cout << " 没有发现可用的相机 " << sInterfaceID << endl;
cout << endl << "结束!" << endl << "按任意键来结束程序:";
int endKey = 0;
cin >> endKey;
pSystem->Close();
SystemList::ReleaseInstance();
return returncode;
}
else
{
pInterface = (*interfaceList)[sInterfaceID];// 获取接口名称
}
// 获取设备列表以及设备
cout << "设备列表" << endl;
cout << "########" << endl << endl;
//
try
{
// 对可获取的相机计数
deviceList = pInterface->GetDevices();
deviceList->Refresh(100);
cout << "检测到的设备个数: " << deviceList->size() << endl;
//DEVICE INFORMATION BEFORE OPENING
for (DeviceList::iterator devIterator = deviceList->begin(); devIterator != deviceList->end(); devIterator++)
{
cout << " 设备的ID: " << devIterator->first << endl;
cout << " 设备模型: " << devIterator->second->GetModel() << endl;
cout << " 设备序列号: " << devIterator->second->GetSerialNumber() << endl;
cout << " 设备制造商: " << devIterator->second->GetVendor() << endl;
cout << " Device TLType: " << devIterator->second->GetTLType() << endl;
cout << " 设备的接口状态: " << devIterator->second->GetAccessStatus() << endl;
cout << " 设备的用户ID: " << devIterator->second->GetDisplayName() << endl << endl;
}
}
catch (Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型:" << ex.GetType() << endl;
cout << "异常描述:" << ex.GetErrorDescription() << endl;
cout << "发生异常的功能:" << ex.GetFunctionName() << endl;
}
cout << "DEVICE" << endl;
cout << "######" << endl << endl;
// 打开相机列表中的第一台相机
try
{
for (DeviceList::iterator devIterator = deviceList->begin(); devIterator != deviceList->end(); devIterator++)
{
try
{
cout << " 打开第一台设备 " << endl;
cout << " 设备的ID: " << devIterator->first << endl;
cout << " 设备模型: " << devIterator->second->GetModel() << endl;
cout << " 设备序列号: " << devIterator->second->GetSerialNumber() << endl;
cout << " 设备制造商: " << devIterator->second->GetVendor() << endl;
cout << " Device TLType: " << devIterator->second->GetTLType() << endl;
cout << " 设备的接口状态: " << devIterator->second->GetAccessStatus() << endl;
cout << " 设备的用户ID: " << devIterator->second->GetDisplayName() << endl << endl;
devIterator->second->Open();
sDeviceID = devIterator->first;
cout << " 已打开的设备 - 远程节点列表信息 " << endl;
cout << " 设备接口状态: " << devIterator->second->GetAccessStatus() << endl;
// 序列号
if(devIterator->second->GetRemoteNodeList()->GetNodePresent("DeviceSerialNumber"))
cout << " 设备的序列号: " << devIterator->second->GetRemoteNode("DeviceSerialNumber")->GetValue() << endl;
else if(devIterator->second->GetRemoteNodeList()->GetNodePresent("DeviceID"))
cout << " 设备ID (SN): " << devIterator->second->GetRemoteNode("DeviceID")->GetValue() << endl;
else
cout << " 序列号: Not Available " << endl;
cout << " " << endl;
break;
}
catch (BGAPI2::Exceptions::ResourceInUseException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << " Device " << devIterator->first << " already opened " << endl;
cout << " ResourceInUseException: " << ex.GetErrorDescription() << endl;
}
catch (BGAPI2::Exceptions::AccessDeniedException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << " 设备 " << devIterator->first << " 已经被打开 " << endl;
cout << " 接口拒绝异常 " << ex.GetErrorDescription() << endl;
}
}
}
catch (Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型:" << ex.GetType() << endl;
cout << "异常描述:" << ex.GetErrorDescription() << endl;
cout << "发生异常的功能:" << ex.GetFunctionName() << endl;
}
// 检查设备是否存在。
if (sDeviceID == "")
{
cout << " 设备不存在: " << sDeviceID << endl;
cout << endl << "结束!" << endl << "按任意键来结束程序:";
int endKey = 0;
cin >> endKey;
pInterface->Close();
pSystem->Close();
SystemList::ReleaseInstance();
return returncode;
}
else
{
pDevice = (*deviceList)[sDeviceID];
}
cout << " 设置设备参数 " << endl;
cout << "######################" << endl << endl;
cout << " 数据流列表 " << endl;
cout << "################" << endl << endl;
try
{
// 对可以获得的数据流计数
datastreamList = pDevice->GetDataStreams();// 获取数据流
datastreamList->Refresh();
cout << "检测到的数据流: " << datastreamList->size() << endl;
// 在设备打开之前显示数据流信息
for (DataStreamList::iterator dstIterator = datastreamList->begin(); dstIterator != datastreamList->end(); dstIterator++)
{
cout << " 数据流 ID: " << dstIterator->first << endl << endl;
}// end for
}
catch(Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型: " << ex.GetType() << endl;
cout << "异常描述: " << ex.GetErrorDescription() << endl;
cout << "发生异常的功能: " << ex.GetFunctionName() << endl;
}
cout << " 数据流 " << endl;
cout << "############" << endl << endl;
// 打开数据流列表中的第一个数据流
try
{
for (DataStreamList::iterator dstIterator = datastreamList->begin(); dstIterator != datastreamList->end(); dstIterator++)
{
cout << "打开第一个数据流 " << endl;
cout << "数据流 ID: " << dstIterator->first << endl << endl;
dstIterator->second->Open();
sDataStreamID = dstIterator->first;
cout << " 已打开的数据流 - 节点列表信息 " << endl;
cout << " 数据流声明缓存最小值: " << dstIterator->second->GetNode("StreamAnnounceBufferMinimum")->GetValue() << endl;
if( dstIterator->second->GetTLType() == "GEV" )
{
cout << " 数据流驱动模型: " << dstIterator->second->GetNode("StreamDriverModel")->GetValue() << endl;
}
cout << " " << endl;
break;
}
}
catch(Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型: " << ex.GetType() << endl;
cout << "异常描述: " << ex.GetErrorDescription() << endl;
cout << "发生异常的功能: " << ex.GetFunctionName() << endl;
}
// 检查数据流是否存在。
if (sDataStreamID == "")
{
cout << " 没有找到数据流 " << sDataStreamID << endl;
cout << endl << "结束!" << endl << "按任意键结束程序:";
int endKey = 0;
cin >> endKey;
pDevice->Close();
pInterface->Close();
pSystem->Close();
SystemList::ReleaseInstance();
return returncode;
}
else
{
pDataStream = (*datastreamList)[sDataStreamID];
}
cout << " 缓存列表" << endl;
cout << "##############" << endl << endl;
try
{
// 数据流列表
bufferList = pDataStream->GetBufferList();
// 以内部缓存模式使用4个缓存
for(int i=0; i<4; i++)
{
pBuffer = new Buffer();
bufferList->Add(pBuffer);// 添加缓存
}
cout << "已声明的缓存: " << bufferList->GetAnnouncedCount() << " 使用 " << pBuffer->GetMemSize() * bufferList->GetAnnouncedCount() << " [bytes]" << endl;
}
catch(Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型: " << ex.GetType() << endl;
cout << "异常描述: " << ex.GetErrorDescription() << endl;
cout << "发生异常的功能: " << ex.GetFunctionName() << endl;
}
try
{
for (BufferList::iterator bufIterator = bufferList->begin(); bufIterator != bufferList->end(); bufIterator++)
{
bufIterator->second->QueueBuffer();
}
cout << "队列中的缓存数: " << bufferList->GetQueuedCount() << endl;
}
catch(Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型: " << ex.GetType() << endl;
cout << "异常描述: " << ex.GetErrorDescription() << endl;
cout << "发生异常的功能: " << ex.GetFunctionName() << endl;
}
cout << " " << endl;
cout << "相机开始工作" << endl;
cout << "############" << endl << endl;
// 开始获取数据流
try
{
pDataStream->StartAcquisitionContinuous();
cout << "开启数据流 " << endl;
}
catch(Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型: " << ex.GetType() << endl;
cout << "异常描述: " << ex.GetErrorDescription() << endl;
cout << "发生异常的功能: " << ex.GetFunctionName() << endl;
}
// 开启相机
try
{
cout << "相机" << pDevice->GetModel() << " 开始工作 " << endl;
pDevice->GetRemoteNode("AcquisitionStart")->Execute();
}
catch(Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型: " << ex.GetType() << endl;
cout << "异常描述: " << ex.GetErrorDescription() << endl;
cout << "发生异常的功能: " << ex.GetFunctionName() << endl;
}
// 捕获十张图像
cout << " " << endl;
cout << "以软触发模式捕获十张图像" << endl;
cout << "#####################################" << endl << endl;
Buffer * pBufferFilled = NULL;
try
{
Image * pImage = NULL;// 图像对象
for(int i = 0; i < 100; i++)
{
// 打开软件触发模式
cout << " 执行软件触发模式: " << i+1 << " 是接口类型 " << pDevice->GetRemoteNode("TriggerSoftware")->GetInterface() << endl;
pDevice->GetRemoteNode("TriggerSoftware")->Execute();
// 等待图像
pBufferFilled = pDataStream->GetFilledBuffer(1000); //每1s捕获一张图像
if(pBufferFilled == NULL)
{
cout << "Error: Buffer Timeout after 1000 msec" << endl;
}
else if(pBufferFilled->GetIsIncomplete() == true)
{
cout << "Error: Image is incomplete" << endl;
// queue buffer again
pBufferFilled->QueueBuffer();
}
else
{
cout << " 图像 " << std::setw(5) << pBufferFilled->GetFrameID() << " 保存在地址: " << hex << pBufferFilled->GetMemPtr() << dec << endl;
Image * pTransformImage = NULL;
if (pImage == NULL)
pImage = imgProcessor->CreateImage( (bo_uint)pBufferFilled->GetWidth(), (bo_uint)(int)pBufferFilled->GetHeight(), pBufferFilled->GetPixelFormat(), pBufferFilled->GetMemPtr(), pBufferFilled->GetMemSize() );
else
pImage->Init((bo_uint)pBufferFilled->GetWidth(), (bo_uint)(int)pBufferFilled->GetHeight(), pBufferFilled->GetPixelFormat(), pBufferFilled->GetMemPtr(), pBufferFilled->GetMemSize());
cout << " pImage.Pixelformat: " << pImage->GetPixelformat() << endl;
cout << " pImage.Width: " << pImage->GetWidth() << endl;
cout << " pImage.Height: " << pImage->GetHeight() << endl;
cout << " pImage.Buffer: " << hex << pImage->GetBuffer() << dec << endl;
// 转换成BGR图像
pTransformImage = imgProcessor->CreateTransformedImage(pImage, "BGR8");
cout << " Image " << setw(5) << pBufferFilled->GetFrameID() << " transformed to BGR8" << endl;
cout << " pTransformImage.Pixelformat: " << pTransformImage->GetPixelformat() << endl;
cout << " pTransformImage.Width: " << pTransformImage->GetWidth() << endl;
cout << " pTransformImage.Height: " << pTransformImage->GetHeight() << endl;
cout << " pTransformImage.Buffer: " << hex << pTransformImage->GetBuffer() << dec << endl;
cout << " Bytes per image: " << (long)((pTransformImage->GetWidth())*(pTransformImage->GetHeight())*3.0) << endl;
cout << " Bytes per pixel: " << 3.0 << endl;
string image_path = "D:\\相机图像\\" + to_string(long long(i+1)) + ".jpg";
cout<GetHeight()), int(pTransformImage->GetWidth()), CV_8UC3, pTransformImage->GetBuffer());
cout<Release();
// queue buffer again
pBufferFilled->QueueBuffer();
}
}
}
catch(Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "异常类型: " << ex.GetType() << endl;
cout << "异常描述: " << ex.GetErrorDescription() << endl;
cout << "发生异常的功能: " << ex.GetFunctionName() << endl;
}
cout << " " << endl;
cout << "相机停止工作" << endl;
cout << "###########" << endl << endl;
try
{
//SEARCH FOR 'AcquisitionAbort'
if(pDevice->GetRemoteNodeList()->GetNodePresent("AcquisitionAbort"))
{
pDevice->GetRemoteNode("AcquisitionAbort")->Execute();
cout << "5.1.12 " << pDevice->GetModel() << " aborted " << endl;
}
pDevice->GetRemoteNode("AcquisitionStop")->Execute();
cout << "5.1.12 " << pDevice->GetModel() << " stopped " << endl;
cout << endl;
BGAPI2::String sExposureNodeName = "";
if (pDevice->GetRemoteNodeList()->GetNodePresent("ExposureTime")) {
sExposureNodeName = "ExposureTime";
}
else if (pDevice->GetRemoteNodeList()->GetNodePresent("ExposureTimeAbs")) {
sExposureNodeName = "ExposureTimeAbs";
}
cout << " ExposureTime: " << fixed << setprecision(0) << pDevice->GetRemoteNode(sExposureNodeName)->GetDouble() << " [" << pDevice->GetRemoteNode(sExposureNodeName)->GetUnit() << "]" << endl;
if( pDevice->GetTLType() == "GEV" )
{
if(pDevice->GetRemoteNodeList()->GetNodePresent("DeviceStreamChannelPacketSize"))
cout << " DeviceStreamChannelPacketSize: " << pDevice->GetRemoteNode("DeviceStreamChannelPacketSize")->GetInt() << " [bytes]" << endl;
else
cout << " GevSCPSPacketSize: " << pDevice->GetRemoteNode("GevSCPSPacketSize")->GetInt() << " [bytes]" << endl;
cout << " GevSCPD (PacketDelay): " << pDevice->GetRemoteNode("GevSCPD")->GetInt() << " [tics]" << endl;
}
cout << endl;
}
catch (Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
cout << "ExceptionType: " << ex.GetType() << endl;
cout << "ErrorDescription: " << ex.GetErrorDescription() << endl;
cout << "in function: " << ex.GetFunctionName() << endl;
}
//STOP DataStream acquisition
try
{
if( pDataStream->GetTLType() == "GEV" )
{
//DataStream Statistic
std::cout << " DataStream Statistics " << std::endl;
std::cout << " DataBlockComplete: " << pDataStream->GetNodeList()->GetNode("DataBlockComplete")->GetInt() << std::endl;
std::cout << " DataBlockInComplete: " << pDataStream->GetNodeList()->GetNode("DataBlockInComplete")->GetInt() << std::endl;
std::cout << " DataBlockMissing: " << pDataStream->GetNodeList()->GetNode("DataBlockMissing")->GetInt() << std::endl;
std::cout << " PacketResendRequestSingle: " << pDataStream->GetNodeList()->GetNode("PacketResendRequestSingle")->GetInt() << std::endl;
std::cout << " PacketResendRequestRange: " << pDataStream->GetNodeList()->GetNode("PacketResendRequestRange")->GetInt() << std::endl;
std::cout << " PacketResendReceive: " << pDataStream->GetNodeList()->GetNode("PacketResendReceive")->GetInt() << std::endl;
std::cout << " DataBlockDroppedBufferUnderrun: " << pDataStream->GetNodeList()->GetNode("DataBlockDroppedBufferUnderrun")->GetInt() << std::endl;
std::cout << " Bitrate: " << pDataStream->GetNodeList()->GetNode("Bitrate")->GetDouble() << std::endl;
std::cout << " Throughput: " << pDataStream->GetNodeList()->GetNode("Throughput")->GetDouble() << std::endl;
std::cout << std::endl;
}
if( pDataStream->GetTLType() == "U3V" )
{
//DataStream Statistic
std::cout << " DataStream Statistics " << std::endl;
std::cout << " GoodFrames: " << pDataStream->GetNodeList()->GetNode("GoodFrames")->GetInt() << std::endl;
std::cout << " CorruptedFrames: " << pDataStream->GetNodeList()->GetNode("CorruptedFrames")->GetInt() << std::endl;
std::cout << " LostFrames: " << pDataStream->GetNodeList()->GetNode("LostFrames")->GetInt() << std::endl;
std::cout << std::endl;
}
//BufferList Information
std::cout << " BufferList Information " << std::endl;
std::cout << " DeliveredCount: " << bufferList->GetDeliveredCount() << std::endl;
std::cout << " UnderrunCount: " << bufferList->GetUnderrunCount() << std::endl;
std::cout << std::endl;
pDataStream->StopAcquisition();
std::cout << "5.1.12 DataStream stopped " << std::endl;
bufferList->DiscardAllBuffers();
}
catch (BGAPI2::Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
std::cout << "ExceptionType: " << ex.GetType() << std::endl;
std::cout << "ErrorDescription: " << ex.GetErrorDescription() << std::endl;
std::cout << "in function: " << ex.GetFunctionName() << std::endl;
}
std::cout << std::endl;
std::cout << "RELEASE" << std::endl;
std::cout << "#######" << std::endl << std::endl;
//Release buffers
std::cout << "5.1.13 Releasing the resources " << std::endl;
try
{
while( bufferList->size() > 0)
{
pBuffer = bufferList->begin()->second;
bufferList->RevokeBuffer(pBuffer);
delete pBuffer;
}
std::cout << " buffers after revoke: " << bufferList->size() << std::endl;
pDataStream->Close();
pDevice->Close();
pInterface->Close();
pSystem->Close();
BGAPI2::SystemList::ReleaseInstance();
}
catch (BGAPI2::Exceptions::IException& ex)
{
returncode = 0 == returncode ? 1 : returncode;
std::cout << "ExceptionType: " << ex.GetType() << std::endl;
std::cout << "ErrorDescription: " << ex.GetErrorDescription() << std::endl;
std::cout << "in function: " << ex.GetFunctionName() << std::endl;
}
std::cout << std::endl;
std::cout << "End" << std::endl << std::endl;
std::cout << "Input any number to close the program:";
int endKey = 0;
std::cin >> endKey;
return returncode;
}