首页 > 解决方案 > 编译器找不到链接的 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 但我开始了一个新话题,因为问题的重点已经改变。

标签: c++opencv

解决方案


...现在我通过深入研究 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了。感谢所有试图提供帮助的人。


推荐阅读