我试图获得一个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 5是Basler自己的库,/usr/local/include链接到opencv4文件夹。
我得到了一个长达一页的错误消息列表--开始类似于这个GrabV3.cpp:(.text+0x2a5):对Pylon::CDeviceInfo::CDeviceInfo()' GrabV3.cpp:(.text+0x370): undefined reference to
__Pylon::CInstantCamera::CInstantCamera(Pylon::IPylonDevice,的未定义引用:(.text+0x346):未定义的对Pylon::CDeviceInfo::CDeviceInfo()' GrabV3.cpp:(.text+0x370): undefined reference to
__Pylon::CInstantCamera::CInstantCamera(Pylon::IPylonDevice,的引用Pylon::CInstantCamera::Open()' GrabV3.cpp:(.text+0x39d): undefined reference to
Pylon::CInstantCamera::GetNodeMap()‘GrabV3.cpp:(.text+0x38e):未定义对GenICam_3_1_Basler_pylon::gcstring::gcstring(char const*)' GrabV3.cpp:(.text+0x488): undefined reference to
GenICam_3_1_Basler_pylon::gcstring::~gcstring()’GrabV3.cpp的引用:(.text+0x3cb):未定义的对GenICam_3_1_Basler_pylon::gcstring::gcstring(char const*)' GrabV3.cpp:(.text+0x488): undefined reference to
GenICam_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 to
GenICam_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 to
GenICam_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 to
GenICam_3_1_Basler_pylon::gcstring::~gcstring()’GrabV3.cpp的未定义引用:(.text+0x745):未定义的对`cv::VideoWriter::open的引用(cv::String&,cv::Size_,bool)'*
因此,显然什么都不起作用,从cv:VideoWriter()函数开始,它是标准OpenCV (我使用本教程:https://cv-tricks.com/installation/opencv-4-1-ubuntu18-04/安装的)的一部分。
所以我在这里迷路了--我已经花了一天的时间试着让它发挥作用。有人能帮忙吗?
发布于 2019-10-03 14:10:24
马克的建议解决了连接问题。然而,由于该软件仍未编译,而且我们仍然处于“编译一个使用Basler相机的程序”的主题中,我将继续讨论范围问题:
g++ $(pkg-config --c阻击--libs opencv4) GrabV3.cpp -i/opt/pylon 5/include-i/opt/pylon 5/include/pylon-L/opt/opencv4/lib64-L/opt/pylon 5/include/ylon5
现在给出以下错误:
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 2/videoio/videoio_C.H中定义的内联函数,由于某些原因,它现在超出了范围。
我试图用暴力把它连在一起
#include "/usr/include/opencv2/videoio/videoio_c.h"
但这导致连接完全搞砸了。谢谢马克让我走了这么远,从这里开始该怎么做?
https://stackoverflow.com/questions/58216404
复制相似问题