cmake 如何构建opencv示例

evrscar2  于 2023-01-13  发布在  其他
关注(0)|答案(2)|浏览(188)

我是cmake的新手,但不是make的新手。这个问题与Could not build OpenCV Android sample project不同,因为另一个问题是关于单个项目的,而这个问题是关于 * 整体 * CMakeLists.txt的。
说到这个考虑${OPENCVDIR}/samples中的CMakeLists.txt
我遵循了cmake的基本流程:

cd  "${OPENCVDIR}/samples"
mkdir build
cd build
cmake ..

但在最后一步我有:

$ cmake ..
CMake Error at CMakeLists.txt:72 (find_package):
  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake

  Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
  "OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"
  provides a separate development package or SDK, be sure it has been
  installed.

-- Configuring incomplete, errors occurred!
See also "/git/opencv/samples/CMakeFiles/CMakeOutput.log".

第72行是这样的:find_package(OpenCV REQUIRED PATHS "..")
我查看了错误日志,没有提供任何信息。

Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"

The CXX compiler identification is GNU, found in "/git/opencv/samples/CMakeFiles/3.13.4/CompilerIdCXX/a.out"

Determining if the C compiler works passed with the following output:
Change Dir: /git/opencv/samples/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_26f76/fast"
/usr/bin/make -f CMakeFiles/cmTC_26f76.dir/build.make CMakeFiles/cmTC_26f76.dir/build
make[1]: Entering directory '/git/opencv/samples/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o
/usr/bin/cc    -o CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o   -c /git/opencv/samples/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_26f76
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_26f76.dir/link.txt --verbose=1
/usr/bin/cc      -rdynamic CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o  -o cmTC_26f76
make[1]: Leaving directory '/git/opencv/samples/CMakeFiles/CMakeTmp'

Detecting C compiler ABI info compiled with the following output:
"/git/opencv/samples/CMakeFiles/CMakeOutput.log" 706 lines, 48095 characters
    Feature record: CXX_FEATURE:0cxx_defaulted_move_initializers
    Feature record: CXX_FEATURE:0cxx_delegating_constructors
    Feature record: CXX_FEATURE:0cxx_deleted_functions
    Feature record: CXX_FEATURE:0cxx_digit_separators
    Feature record: CXX_FEATURE:0cxx_enum_forward_declarations
    Feature record: CXX_FEATURE:0cxx_explicit_conversions
    Feature record: CXX_FEATURE:0cxx_extended_friend_declar
   etc ..

构建这些示例的正确方法是什么-希望使用已经提供的CMakeLists.txt

5gfr0r5j

5gfr0r5j1#

cmake似乎找不到OpenCV的安装目录,尝试通过参数提供值:

cmake -DCMAKE_PREFIX_PATH=/home/someone/src/opencv/install ..

如果它工作的话,你可以在顶层CMakeLitst.txt中定义它:

list(APPEND CMAKE_PREFIX_PATH /home/someone/src/opencv/install)

这应该为CMake提供了它应该关注的地方。

m528fe3b

m528fe3b2#

$ opencv_version
3.4.16
$ cd OpenCV/samples/
$ cmake -B build
$ cmake --build build
  • JPEG显示
$ build/cpp/example_cpp_image data/lena.jpg
  • USB摄像头捕获
$ build/cpp/example_cpp_videocapture_basic
$ build/cpp/example_cpp_videocapture_camera
  • AI识别
$ build/tapi/example_tapi_hog

相关问题