编译使用Basler相机的程序

Compiling a program for using a Basler Camera

本文关键字:程序 相机 Basler 编译      更新时间:2023-10-16

我正在尝试使用Basler相机拍摄图像的C++程序。我得到了 来自制造商的代码,它应该是"非常易于使用的",但是,链接它有 成为一场噩梦。我的C++时间已经过去了(最近才使用 Matlab(,所以我可能会犯一些愚蠢的错误,但请启发我:

代码如下所示:

// 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;
using namespace GenApi;

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/video/video.hpp>
//#include <opencv2/videoio.hpp>
using namespace cv;


// Namespace for using cout.
using namespace std;
#include <stdio.h>
#include "kbhit.h"
#include <sys/stat.h>  // for checking the file size
#include <sstream>
// 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;
VideoWriter cvVideoCreator;
struct stat statbuf;
string filenameBase = "/opt/PylonTestAVI";
uint filecounter = 1;
string filename = "";
... (and so on)

我正在尝试使用以下方法编译它:

g++ GrabV3.cpp -I/opt/pylon5 -I/opt/pylon5/include -I/usr/local/include -I/usr/include/ -L/opt/pylon5/lib64 

此处/opt/pylon5 是 Basler 自己的库和 opencv4 文件夹的链接。

我收到一个长达一页的错误消息列表 - 开始看起来像这样GrabV3.cpp:(.text+0x2a5(: 对cv::VideoWriter::VideoWriter()' GrabV3.cpp:(.text+0x32a): undefined reference toPylon::CTlFactory::GetInstance((' 的未定义引用 GrabV3.cpp:(.text+0x346(: 对Pylon::CDeviceInfo::CDeviceInfo()' GrabV3.cpp:(.text+0x370): undefined reference toPylon::CInstantCamera::CInstantCamera(Pylon::IPylonDevice, Pylon::ECleanup(的未定义引用 GrabV3.cpp:(.text+0x38e(: 对Pylon::CInstantCamera::Open()' GrabV3.cpp:(.text+0x39d): undefined reference toPylon::CInstantCamera::GetNodeMap((' 的未定义引用 GrabV3.cpp:(.text+0x3cb(: 对GenICam_3_1_Basler_pylon::gcstring::gcstring(char const*)' GrabV3.cpp:(.text+0x41b): undefined reference toGenICam_3_1_Basler_pylon::gcstring::~gcstring((' 的未定义引用 GrabV3.cpp:(.text+0x465(: 对GenICam_3_1_Basler_pylon::gcstring::gcstring(char const*)' GrabV3.cpp:(.text+0x488): undefined reference toGenICam_3_1_Basler_pylon::gcstring::~gcstring((' 的未定义引用 GrabV3.cpp:(.text+0x4af(: 对GenICam_3_1_Basler_pylon::gcstring::gcstring(char const*)' GrabV3.cpp:(.text+0x4ff): undefined reference toGenICam_3_1_Basler_pylon::gcstring::~gcstring((' 的未定义引用 GrabV3.cpp:(.text+0x526(: 对GenICam_3_1_Basler_pylon::gcstring::gcstring(char const*)' GrabV3.cpp:(.text+0x576): undefined reference toGenICam_3_1_Basler_pylon::gcstring::~gcstring((' 的未定义引用 GrabV3.cpp:(.text+0x745(: 未定义引用 'cv::VideoWriter::open(cv::String const&, int, double, cv::Size_, bool('*

所以显然没有任何效果,从 cv:VideoWriter(( 函数开始,它是标准 OpenCV 的一部分(我使用本教程安装:https://cv-tricks.com/installation/opencv-4-1-ubuntu18-04/(。

所以我在这里迷路了——已经花了大约一天的时间试图让它工作。有人可以帮忙吗?

好的,所以马克的建议解决了链接问题。但是,由于软件仍未编译,并且我们仍处于"编译使用Basler相机的程序"主题中,因此我将继续解决范围问题:

g++ $(pkg-config --cflags --libs opencv4( GrabV3.cpp

-I/opt/pylon5/include -I/opt/pylon5/include/pylon -L/opt/pylon5/lib64 -L/opt/pylon5/include/pylon5/include/pylon(包括/pylon(现在给出以下错误:

GrabV3.cpp: In function ‘int main(int, char**)’:
GrabV3.cpp:84:32: error: ‘CV_FOURCC’ was not declared in this scope
cvVideoCreator.open(filename,CV_FOURCC('D','I','V','X'),20,FrameSize,true);

在"等等"之后(请参阅我的第一篇文章(,代码继续如下:

try
{
// Create an instant camera object with the camera device found first.
CInstantCamera camera( CTlFactory::GetInstance().CreateFirstDevice());
camera.Open();
INodeMap& nodeMap = camera.GetNodeMap();
CEnumerationPtr TestImageSelector = nodeMap.GetNode("TestImageSelector");
TestImageSelector->FromString("Testimage4");
CIntegerPtr Width = nodeMap.GetNode("Width");
CIntegerPtr Height = nodeMap.GetNode("Height");
Size FrameSize = Size(Width->GetValue(),Height->GetValue());
stringstream s ;
s<<"_" ;
s<< filecounter;
filename = filenameBase;
filename += s.str() + ".avi";
//cvVideoCreator.open("``/opt/PylonTest_DIVX.avi",CV_FOURCC('M','P','4','2'),20,FrameSize,true);
cvVideoCreator.open(filename,CV_FOURCC('D','I','V','X'),20,FrameSize,true);
//cvVideoCreator.open("/opt/PylonTest.avi",CV_FOURCC('M','J','P','G'),20,FrameSize,true);

// 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;
CImageFormatConverter fc;
fc.OutputPixelFormat = PixelType_BGR8packed;
CPylonImage image;
// 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();
// This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResult;

CV_FOURCC('D','I','V','X'(是一个内联函数,定义在/usr/include/opencv2/videoio/videoio_c.h,现在已经超出了某些人的范围 原因。

我试图通过包含

#include "/usr/include/opencv2/videoio/videoio_c.h"

但这导致链接完全搞砸了。 感谢@Mark让我走到这一步;如何从这里开始?