0

I got a C++ software for grabbing Basler camera images from the manufacturer; now I'm trying to make it work.

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

...

I am trying to compile this using

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 

but I'm getting the error message

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

I don't understand this as CV_FOURCC('D','I','V','X') is an inline function defined in /usr/include/opencv2/videoio/videoio.h, which should clearly be part of the include path.

What is wrong?

I started this discussion here: Compiling a program for using a Basler Camera but I am starting a new topic because the emphasis of the problem has changed.

mikael
  • 49
  • 6
  • Please provide a [mcve] – Thomas Sablik Oct 14 '19 at 12:17
  • What version of OCV are you using? – Croolman Oct 14 '19 at 12:18
  • 1
    Where do you include opencv2/videoio/videoio.h? – Thomas Sablik Oct 14 '19 at 12:20
  • 1
    Does this solve your problem: https://stackoverflow.com/questions/51624448/opencv-3-error-cv-fourcc-identifier-not-found – Thomas Sablik Oct 14 '19 at 12:27
  • At least got a bit forward: Changing _CV_FOURCC_ to _cv::VideoWriter::fourcc_ at least rid me of the previous error message BUT: now I'm getting a ton of undefined reference errors: GrabV3.cpp:(.text+0x257): undefined reference to `cv::VideoWriter::VideoWriter()' GrabV3.cpp:(.text+0x2dc): undefined reference to `Pylon::CTlFactory::GetInstance()' and so on. – mikael Oct 15 '19 at 11:47
  • Actually what seems to happen is this: If I don't include the opencv2 libraries correctly, I get the same _undefined reference to cv::VideoWriter::VideoWriter()_ The error disappears if I compile using _$(pkg-config --cflags --libs opencv4)_ However, when I correct the CV_FOURCC problem, _the undefined variable error reappars!_ So I'm completely confused here. – mikael Oct 15 '19 at 12:50
  • Okay, changed the compile command to _g++ GrabV3.cpp $(pkg-config --cflags --libs opencv4) -I/opt/pylon5/include -I/opt/pylon5/include/pylon -L/opt/pylon5/lib64 -L/opt/pylon5/include/pylon_ and at least all the VideoGrabber reference errors disappeared. So now it's just a matter of getting the Pylon references correct. – mikael Oct 15 '19 at 14:21

1 Answers1

-1

... and now I solved it by digging into Basler's examples' makefiles. The final litany was this:

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

Pretty proud of myself here; time to learn to use makefiles, I guess. Thanks to all who were trying to help.

mikael
  • 49
  • 6