编译器找不到链接的 OpenCV 库

Compiler not finding a linked OpenCV library

本文关键字:OpenCV 链接 找不到 编译器      更新时间:2023-10-16

我从制造商那里得到了一个C++软件,用于抓取Basler相机图像;现在我正在尝试让它工作。

#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/opencv.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 = "";

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);

我正在尝试使用

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/pylon 

但我收到错误消息

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

我不明白这一点,因为CV_FOURCC("D","I","V","X"(是定义在/usr/include/opencv2/videoio/videoio.h,这显然应该是包含路径的一部分。

怎么了?

我在这里开始了这个讨论: 编译使用Basler相机的程序 但我正在开始一个新话题,因为问题的重点已经改变。

...现在,我通过深入研究Basler示例的makefile来解决它。 最后的连串内容是这样的:

g++ Grab.cpp $(pkg-config --cflags --libs opencv4) -I/opt/pylon5/include -Wl,--enable-new-dtags -Wl,-rpath,/opt/pylon5/lib64 -L/opt/pylon5/lib64 -Wl,-E -lpylonbase -lpylonutility -lGenApi_gcc_v3_1_Basler_pylon -lGCBase_gcc_v3_1_Basler_pylon

我在这里为自己感到非常自豪;我想是时候学习使用makefile了。 感谢所有试图提供帮助的人。