我正在尝试从与Jetson TX1
(Ubuntu 16.04)接口(interface)的Basler相机访问图像。我正在使用OpenCV-C++
和Pylon
库来做到这一点。我正在尝试使用Pylon
链接cmake
。我有以下CMakeLists.txt
文件:
cmake_minimum_required(VERSION 3.5.1)
project(basler_test)
set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl, -E")
find_package(OpenCV REQUIRED)
include_directories(/opt/pylon5/include)
link_directories(/opt/pylon5/lib64)
add_executable(basler_test basler_test.cpp)
target_link_libraries(basler_test ${OpenCV_LIBS} /opt/pylon5/include/pylon/PylonIncludes.h)
cmake .
命令可以正常工作,但是当我执行make
时,它给出了:fatal error: pylon/Platform.h: No such file or directorycompilation terminated
我检查了上面的文件,它确实存在于
PylonIncludes.h
所在的目录中。因此,我相信此错误是因为CMakeLists.txt
中的某些内容未正确设置。我没有足够的经验来创建它们来找出问题所在。请帮助。这是源文件的相关部分:
basler_test.cpp
//This is a test program to check the functionality of Basler dart daA2500-14uc Camera.
#define saveImages 0
#define recordVideo 1
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/video.hpp>
#include <pylon/PylonIncludes.h>
#ifdef PYLON_WIN_BUILD
#include <pylon/PylonGUI.h>
#endif
static const uint32_t c_countOfImagesToGrab = 10;
int main(int argc, char* argv[])
{
...................................
..................................
}
最佳答案
我想这是包括Pylon库的最佳方法。
在CMakeLists.txt中,定义以这种方式在哪里找到Pylon库,
find_package(Pylon QUIET)
if (NOT ${Pylon_FOUND})
include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindPylon.cmake")
endif()
在这里,FindPylon.cmake可以用这种方式编写,
set(PYLON_ROOT $ENV{PYLON_ROOT})
if (NOT DEFINED ENV{PYLON_ROOT})
set(PYLON_ROOT "/opt/pylon5")
endif()
set(_PYLON_CONFIG "${PYLON_ROOT}/bin/pylon-config")
if (EXISTS "${_PYLON_CONFIG}")
set(Pylon_FOUND TRUE)
execute_process(COMMAND ${_PYLON_CONFIG} --cflags-only-I OUTPUT_VARIABLE HEADERS_OUT)
execute_process(COMMAND ${_PYLON_CONFIG} --libs-only-l OUTPUT_VARIABLE LIBS_OUT)
execute_process(COMMAND ${_PYLON_CONFIG} --libs-only-L OUTPUT_VARIABLE LIBDIRS_OUT)
string(REPLACE " " ";" HEADERS_OUT "${HEADERS_OUT}")
string(REPLACE "-I" "" HEADERS_OUT "${HEADERS_OUT}")
string(REPLACE "\n" "" Pylon_INCLUDE_DIRS "${HEADERS_OUT}")
string(REPLACE " " ";" LIBS_OUT "${LIBS_OUT}")
string(REPLACE "-l" "" LIBS_OUT "${LIBS_OUT}")
string(REPLACE "\n" "" Pylon_LIBRARIES "${LIBS_OUT}")
string(REPLACE " " ";" LIBDIRS_OUT "${LIBDIRS_OUT}")
string(REPLACE "-L" "" LIBDIRS_OUT "${LIBDIRS_OUT}")
string(REPLACE "\n" "" LIBDIRS_OUT "${LIBDIRS_OUT}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
foreach (LIBDIR ${LIBDIRS_OUT})
link_directories(${LIBDIR})
endforeach()
else()
set(Pylon_FOUND FALSE)
endif()
然后,您可以通过以下方式将Pylon包含文件包含到您的lib或可执行二进制文件中,
include_directories(
#add other includes directories
${Pylon_INCLUDE_DIRS}
)
您可以通过以下相同方式链接Pylon Lib目录:
$Pylon_LIBRARIES
。希望这对谁会再次参与此问题有所帮助。