工业相机参数设置步骤:
1、查找相机
2、打开相机
3、打开参数节点列表
4、设置参数
//Common Transport Interface(通用传输接口,基于GeniCam协议)
std::string ctiFile("SICKGigEVisionTL.cti");
//GenTL分为两种对象:生产者(producer)和使用者(consumer)。
Sample::Consumer consumer(ctiFile);
//返回传输层的句柄
GenTL::TL_HANDLE tlHandle = consumer.open();
if (tlHandle == GENTL_INVALID_HANDLE)
{
return ;
}
//接口句柄
GenTL::IF_HANDLE interfaceHandle = nullptr;
//设备句柄
GenTL::DEV_HANDLE deviceHandle;
auto tl = consumer.tl();
//查找设备接口,比如说电脑上有两个网口,就是两个接口。
auto interfaces = consumer.getInterfaces(tlHandle);
int input = 0;
//通过索引找到接口,返回接口句柄
Sample::InterfaceId interfaceId = consumer.findInterfaceByIndex(interfaces, input);
if (interfaceId.empty())
{
return ;
}
//通过接口id打开接口,返回接口句柄
interfaceHandle = consumer.openInterfaceById(interfaceId);
if (interfaceHandle == GENTL_INVALID_HANDLE)
{
return ;
}
// Create a NodeMap of the GenTL Producer interface module
// This allows access to GigEVision specific functionality, such as ForceIP,
// that is not part of the GenTL C api.
Sample::GenTLPort interfacePort = Sample::GenTLPort(interfaceHandle, tl);
//获取接口的节点列表,设置和读取相机参数。
GenApi::CNodeMapRef interfaceNodeMap = consumer.getNodeMap(&interfacePort,"InterfacePort");
// Perform a scan, to find devices on the interface
bool8_t changed = false;
//CC是一个宏,判断第二个参数的函数返回值是否正确。
//更新设备列表,并返回是否变化,可以在定时查询设备中使用
CC(tl, tl->IFUpdateDeviceList(interfaceHandle, &changed, 500));
//选取设备
GenApi::CIntegerPtr deviceSelector= interfaceNodeMap._GetNode("DeviceSelector");
deviceSelector->SetValue(input);//重要
//获取设备id
GenApi::CStringPtr deviceId = interfaceNodeMap._GetNode("DeviceID");
if (deviceId->GetValue().empty())
{
return ;
}
std::string deviceIdString = deviceId->GetValue();
//打开设备,返回设备句柄
deviceHandle = consumer.openDeviceById(interfaceHandle, deviceIdString);
//数据流句柄
GenTL::DS_HANDLE dataStreamHandle = consumer.openDataStream(deviceHandle);
if (dataStreamHandle == GENTL_INVALID_HANDLE)
{
return ;
}
Sample::GenTLPort dataStreamPort = Sample::GenTLPort(dataStreamHandle, tl);
GenApi::CNodeMapRef datastreamNodeMap
= consumer.getNodeMap(&dataStreamPort, "StreamPort");
//数据流节点列表
GenApi::CIntegerPtr threadPriority
= datastreamNodeMap._GetNode("StreamThreadPriority");
GenApi::CCommandPtr setStreamPrio
= datastreamNodeMap._GetNode("StreamThreadApplyPriority");
// Default priority is "HIGHEST" = 2, set to TIME CRITICAL = 15
threadPriority->SetValue(15);
setStreamPrio->Execute();
// For logging of receiver statistics after test run, complete list
// of statistics
GenApi::CIntegerPtr seenPacketCount
= datastreamNodeMap._GetNode("GevStreamSeenPacketCount");
GenApi::CIntegerPtr lostPacketCount
= datastreamNodeMap._GetNode("GevStreamLostPacketCount");
GenApi::CIntegerPtr resendPacketCount
= datastreamNodeMap._GetNode("GevStreamResendPacketCount");
GenApi::CIntegerPtr deliveredPacketCount
= datastreamNodeMap._GetNode("GevStreamDeliveredPacketCount");
GenApi::CIntegerPtr unavailablePacketCount
= datastreamNodeMap._GetNode("GevStreamUnavailablePacketCount");
GenApi::CIntegerPtr duplicatePacketCount
= datastreamNodeMap._GetNode("GevStreamDuplicatePacketCount");
GenApi::CIntegerPtr skippedBlockCount
= datastreamNodeMap._GetNode("GevStreamSkippedBlockCount");
GenApi::CIntegerPtr engineUnderrunCount
= datastreamNodeMap._GetNode("GevStreamEngineUnderrunCount");
GenApi::CIntegerPtr discardedBlockCount
= datastreamNodeMap._GetNode("GevStreamDiscardedBlockCount");
GenApi::CIntegerPtr incompleteBlockCount
= datastreamNodeMap._GetNode("GevStreamIncompleteBlockCount");
GenApi::CIntegerPtr oversizedBlockCount
= datastreamNodeMap._GetNode("GevStreamOversizedBlockCount");
// Connect device node map to GenTL
GenTL::PORT_HANDLE devicePort;
CC(tl, tl->DevGetPort(deviceHandle, &devicePort));
Sample::GenTLPort port = Sample::GenTLPort(devicePort, tl);
// Node map for reading/setting device parameters
GenApi::CNodeMapRef device = consumer.getNodeMap(&port);
// Wrapper to be able to access chunk metadata
std::unique_ptr<Sample::ChunkAdapter> chunkAdapter(new Sample::ChunkAdapter(
tl, dataStreamHandle));
chunkAdapter->attachNodeMap(device._Ptr);
GenApi::CIntegerPtr chunkHeight = device._GetNode("ChunkHeight");
GenApi::CIntegerPtr chunkWidth = device._GetNode("ChunkWidth");
// Enable chunk metadata
GenApi::CBooleanPtr chunkModeActive = device._GetNode("ChunkModeActive");
*chunkModeActive = true;
// Switch to 3D
GenApi::CEnumerationPtr deviceType = device._GetNode("DeviceScanType");
*deviceType = "Linescan3D";
// Switch to Continuous Acquisition
GenApi::CEnumerationPtr aquisitionMode = device._GetNode("AcquisitionMode");
*aquisitionMode = "Continuous";
// Set AcquisitionLineRate
GenApi::CFloatPtr acquisitionLineRate = device._GetNode("AcquisitionLineRate");
acquisitionLineRate->SetValue(1000.f);
// Enable Reflectance in addition to Range data
GenApi::CEnumerationPtr regionSelector = device._GetNode("RegionSelector");
*regionSelector = "Scan3dExtraction1";
GenApi::CEnumerationPtr componentSelector
= device._GetNode("ComponentSelector");
*componentSelector = "Range";
GenApi::CIntegerPtr componentIdValue = device._GetNode("ComponentIDValue");
gComponentIdRange = componentIdValue->GetValue();
*componentSelector = "Reflectance";
gComponentIdReflectance = componentIdValue->GetValue();
GenApi::CBooleanPtr reflectanceEnable = device._GetNode("ComponentEnable");
*reflectanceEnable = true;
// Set the number of lines in buffer
GenApi::CIntegerPtr height = device._GetNode("Height");
int64_t bufferHeight = 500;
height->SetValue(bufferHeight);
// Set AOI height
*regionSelector = "Region1";
int64_t aoiHeight = 200;
height->SetValue(aoiHeight);
// Set AOI offset
GenApi::CIntegerPtr offsetY = device._GetNode("OffsetY");
offsetY->SetValue(200);
// Set exposure time for 3D acquisition
GenApi::CFloatPtr exposuretime = device._GetNode("ExposureTime");
exposuretime->SetValue(25.f);
GenApi::CIntegerPtr width = device._GetNode("Width");
GenApi::CIntegerPtr offsetX = device._GetNode("OffsetX");
int64_t aoiOffsetX = offsetX->GetValue();
int64_t aoiOffsetY = offsetY->GetValue();
int64_t bufferWidth = width->GetValue();
// 16-bit range, 8-bit reflectance
int64_t buffer16Size = bufferWidth * bufferHeight * (2 + 1);
// Setup a sufficient amount of buffers
GenApi::CIntegerPtr payload = device._GetNode("PayloadSize");
const size_t payloadSize = static_cast<size_t>(payload->GetValue());
const size_t buffersCount = 20;
Sick Ranger3 相机参数设置
最新推荐文章于 2025-03-20 10:42:24 发布