您的位置:首页 > 编程语言 > C语言/C++

Pylon 以实时图像采集讲解PylonCppSDK使用流程

2015-05-15 13:04 477 查看
在工业控制当中,用到basler工业相机sdk编程,主要是使用c或者c++,当项目庞大时,又需要良好的用户界面,用C++是不错的选择。

以实例和看过的一些参照讲讲PylonCppSDK使用流程,

首先,同C一样,这里给出一个bolg链接,写的不错,http://blog.csdn.net/wenzhou1219/article/details/7543420

从中我们知道,总的开发流程图如下:



那么,用C++开发也大抵如此。

这里我们看一个basler的cpp sample,

This sample illustrates how to grab and process images using the CInstantCamera class.
// Include files to use the PYLON API.
*#include <pylon/PylonIncludes.h>
*#ifdef PYLON_WIN_BUILD*
*#    include <pylon/PylonGUI.h>*
*#endif**

// Namespace for using pylon objects.
using namespace Pylon;

// Namespace for using cout.
using namespace std;

// Number of images to be grabbed.
static const uint32_t c_countOfImagesToGrab = 100;

int main(int argc, char* argv[])
{
// The exit code of the sample application.
int exitCode = 0;

// Automagically call PylonInitialize and PylonTerminate to ensure the pylon runtime system
// is initialized during the lifetime of this object.
Pylon::PylonAutoInitTerm autoInitTerm;

try
{
// Create an instant camera object with the camera device found first.
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());

// Print the model name of the camera.
cout << "Using device " << camera.GetDeviceInfo().GetModelName() << endl;

// The parameter MaxNumBuffer can be used to control the count of buffers
// allocated for grabbing. The default value of this parameter is 10.
camera.MaxNumBuffer = 5;

// Start the grabbing of c_countOfImagesToGrab images.
// The camera device is parameterized with a default configuration which
// sets up free-running continuous acquisition.
camera.StartGrabbing( c_countOfImagesToGrab);

// This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResult;

// Camera.StopGrabbing() is called automatically by the RetrieveResult() method
// when c_countOfImagesToGrab images have been retrieved.
while ( camera.IsGrabbing())
{
// Wait for an image and then retrieve it. A timeout of 5000 ms is used.
camera.RetrieveResult( 5000, ptrGrabResult, TimeoutHandling_ThrowException);

// Image grabbed successfully?
if (ptrGrabResult->GrabSucceeded())
{
// Access the image data.
cout << "SizeX: " << ptrGrabResult->GetWidth() << endl;
cout << "SizeY: " << ptrGrabResult->GetHeight() << endl;
const uint8_t *pImageBuffer = (uint8_t *) ptrGrabResult->GetBuffer();
cout << "Gray value of first pixel: " << (uint32_t) pImageBuffer[0] << endl << endl;

*#ifdef PYLON_WIN_BUILD*
// Display the grabbed image.
Pylon::DisplayImage(1, ptrGrabResult);
*#endif*
}
else
{
cout << "Error: " << ptrGrabResult->GetErrorCode() << " " << ptrGrabResult->GetErrorDescription() << endl;
}
}
}
catch (GenICam::GenericException &e)
{
// Error handling.
cerr << "An exception occurred." << endl
<< e.GetDescription() << endl;
exitCode = 1;
}

// Comment the following two lines to disable waiting on exit.
cerr << endl << "Press Enter to exit." << endl;
while( cin.get() != '\n');

return exitCode;
}


把这个和上面的流程图对比理解,再看看文档和sdk的结构,理解起来就容易多了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息