c++ - 编译器找不到链接的 OpenCV 库
问题描述
我从制造商那里得到了一个用于抓取 Basler 相机图像的 C++ 软件;现在我正在努力让它发挥作用。
#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 中定义的内联函数,它显然应该是包含路径。
怎么了?
我在这里开始了这个讨论: Compiling a program for using a Basler Camera 但我开始了一个新话题,因为问题的重点已经改变。
解决方案
...现在我通过深入研究 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了。感谢所有试图提供帮助的人。
推荐阅读
- sas - ODS Excel/Proc 报告 - 没有自动换行/合并单元格?
- python - 将 python 脚本中的数据通过管道传输到 .csv 或 .txt 文件中
- r - 如何从数据框列表中追加列?
- laravel - 当我使用我的寄存器创建用户时,heroku 返回错误 500
- r - 使用 padr 加厚日期范围,其中起始值与数据框中的日期之一相同
- java - Jar 文件不会与 SWT Mac 一起运行
- kubernetes - 在不分叉的情况下修改 Helm Chart 依赖项的环境变量
- android - 如何在具有平滑滚动的同一布局中拥有两个 recyclerview(先水平然后垂直)
- r - 是否有允许将数值分配给字符的功能?
- wordpress - 在 wordpress 帖子中仅显示指定的自定义分类法