basler pilot系列相机 MFC opencv
采用MFC+ opencv 对basler pilot系列相机,通过千兆以太网接口实现图像数据获取,运行示例程序能够正常获取数据。但是示例程序中相机对象及数据流对象的初始化和数据的获取都是在主函数中的。现在想在mfc中实现单帧图像采集,如果每次采集都去重新获取和初始化相机对象和数据流对象,时间很慢,处理结果就来不及了。尝试着把初始化部分和数据采集部分分开,放在不同的函数中,程序调试时出现莫名的错误。想不明白是为什么。不是语法错误。
相机初始化代码:
[cpp]
BOOL CPylonGrabView::OnInitialCamera()
{
Pylon::PylonAutoInitTerm autoInitTerm;
try
{
CTlFactory& TlFactory= CTlFactory::GetInstance();
/* ITransportLayer **/pTl = TlFactory.CreateTl( Camera_t::DeviceClass() );
DeviceInfoList_t devices;
if ( 0 == pTl->EnumerateDevices( devices ) )// Enumerate GigE cameras
{
MessageBox(_T("相机不存在,请确认相机是否正确连接!"));
TRACE("==================No camera present!====================\n");
m_bIsCameraPresent = FALSE;
return FALSE;
}
m_bIsCameraPresent = TRUE;
//Camera_t Camera = pTl->CreateDevice(devices[0]) ;// Create a camera object
m_Camera.Attach( pTl->CreateDevice(devices[0]));
m_Camera.Open();// Open the camera object
//========== Parameterize the camera
m_Camera.PixelFormat.SetValue(PixelFormat_BayerBG8);// Bayer BG 8 pixel format*/
m_Camera.Width.SetValue( m_iwidth);// Maximized AOI
m_Camera.Height.SetValue( m_iheight);
m_Camera.OffsetX.SetValue( m_ioffset_x );
m_Camera.OffsetY.SetValue( m_ioffset_y );
// Continuous mode, software trigger used
m_Camera.TriggerSelector.SetValue(TriggerSelector_AcquisitionStart);
m_Camera.TriggerMode.SetValue( TriggerMode_On );
m_Camera.AcquisitionMode.SetValue( AcquisitionMode_SingleFrame );
m_Camera.TriggerSource.SetValue( TriggerSource_Software );
m_Camera.ExposureMode.SetValue( ExposureMode_Timed ); // Configure exposure time and mode
m_Camera.ExposureTimeRaw.SetValue( 200);
// Get and open a stream grabber
/*CBaslerGigECamera::StreamGrabber_t */StreamGrabber.Attach(m_Camera.GetStreamGrabber(0));
StreamGrabber.Open();
const int bufferSize = (int) m_Camera.PayloadSize();
const int numBuffers = 10;
StreamGrabber.MaxBufferSize = bufferSize;
StreamGrabber.MaxNumBuffer = numBuffers;
StreamGrabber.PrepareGrab();
// Allocate and register image buffers, put them into the
// grabber’s input queue
unsigned char* ppBuffers[numBuffers];
MyContext context[numBuffers];
StreamBufferHandle handles[numBuffers];
for ( int i = 0; i < numBuffers; ++i )
{
ppBuffers[i] = new unsigned char[bufferSize];
handles[i] = StreamGrabber.RegisterBuffer( ppBuffers[i], bufferSize);
StreamGrabber.QueueBuffer( handles[i], &context[i] );
}
}
catch( GenICam::GenericException &e )// Error handling
{
TRACE("==========================An exception occurred!==================\n", e.GetDescription());
MessageBox(e.GetDescription(),NULL,MB_OK );
return FALSE;
}
}
图像采集代码:
[cpp]
BOOL CPylonGrabView::Grab()
{
StartCounter();
try
{
//IStreamGrabber* pGrabber = m_Camera.GetStreamGrabber(0);
// CBaslerGigECamera::StreamGrabber_t StreamGrabber =
// m_Camera.GetStreamGrabber(0);
/*StreamGrabber.Open();*/
// Parameterize the stream grabber
//const int bufferSize = (int) m_Camera.PayloadSize();
//const int numBuffers = 10;
//StreamGrabber.MaxBuf ferSize = bufferSize;
//StreamGrabber.MaxNumBuffer = numBuffers;
//StreamGrabber.PrepareGrab();
//// Allocate and register image buffers, put them into the
//// grabber’s input queue
//unsigned char* ppBuffers[numBuffers];
补充:软件开发 , C++ ,