繁体   English   中英

cmake在opencv c ++项目中不起作用

[英]cmake is not working in opencv c++ project

我需要你的帮助 ! 我在这个链接中有这个C ++代码

[链接] https://github.com/royshil/FoodcamClassifier

我已经尝试了两天来比较它,我失败了他们说我必须使用cmake,我已经尝试了“GUI版本,它给了我错误的cmake本身。所以我采取了cpp和头文件并创建了一个新项目,但我现在有100个与opencv库有关的错误,我向上帝发誓我确定包含文件夹和它在我的项目中的库!不知道是什么问题与它!

任何的想法 ?

这是错误:

'CMake Error: Unable to open cache file for save. C:/Program Files/CMake 2.8/bin/CMakeCache.txt
CMake Error at CMakeLists.txt:4 (FIND_PACKAGE):
  Could not find module FindOpenCV.cmake or a configuration file for package
  OpenCV.

  Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
  directory containing a CMake configuration file for OpenCV.  The file will
  have one of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake



OpenCV_DIR-NOTFOUND
Configuring incomplete, errors occurred!
CMake Error: Unable to open cache file for save. C:/Program Files/CMake 2.8/bin/CMakeCache.txt
CMake Error: : System Error: Permission denied
CMake Error: : System Error: Permission denied '

您可能需要在行FIND_PACKAGE(OpenCV Required) 之前CMakeLists.txt添加以下代码(在我的情况下)

SET("OpenCV_DIR" "PATH/TO/CMake/build")

在我的安装中它解决了问题,因为提到的文件位于build文件夹中。

所以,这就是为我解决的问题。

首先, 如果有疑问 - 在尝试添加其他路径/值/ mod之前,请务必记住清除CMake“缓存” 我知道这看起来有点奇怪,但以前尝试解决问题的遗产可能会阻碍真正的问题。 最简单的方法是从轨道上钻取你的源外“构建”目录(唯一的方法是确定),然后再试一次......

其次,从根本上说, 这里的目标编译器和架构是什么以及您下载的OpenCV版本提供了什么? 例如,截至编写OpenCV 3.1预构建的安装程序时,我下载了~\\build\\x64\\vc12 & vc14 - 这当然是针对VisualStudio 2012和2014构建的。

我使用Mingw并定位x86 - 所以我下载了源代码(通过github发布作为*.zip文件)并在\\opencv文件夹中执行了以下步骤:

mkdir build
cd build
cmake -G  "MinGW Makefiles" ..
cmake --build .
cmake --build . --target install

您当然可以通过各种开关控制构建,还可以指定安装的位置。

执行“安装”步骤 - 默认情况下将最终库等复制到名为“install”的文件夹中 - 是关键,因为它正确地将所有生成的库和文件放在正确的位置并包含神奇的OpenCVConfig.cmake文件在顶部。

因此,我终于可以指向我的项目CMakeLists.txt文件以解决OpenCV:

set("OpenCV_DIR" "C:/Code/opencv/build/install")

find_package( OpenCV REQUIRED )

并且,确保生成的可执行文件知道* .dll:

PATH=%PATH%;C:\Code\opencv\build\install\x86\mingw\bin

在Linux上我做了以下事情:

$ git clone https://github.com/royshil/FoodcamClassifier.git
$ cd FoodcamClassifier/
$ mkdir build
$ cd build/
$ cmake ../

-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
/usr/local/share/OpenCV
-- Configuring done
-- Generating done
-- Build files have been written to: /home/cog/workspace/opencv/FoodcamClassifier/build

$ make

Scanning dependencies of target build-vocabulary
[  8%] Building CXX object CMakeFiles/build-vocabulary.dir/build_vocabolary.cpp.o
Linking CXX executable build-vocabulary
[  8%] Built target build-vocabulary
Scanning dependencies of target foodcam-predict
[ 16%] Building CXX object CMakeFiles/foodcam-predict.dir/foodcam_predict.cpp.o
[ 25%] Building CXX object CMakeFiles/foodcam-predict.dir/predict_common.cpp.o
Linking CXX executable foodcam-predict
[ 25%] Built target foodcam-predict
Scanning dependencies of target kmeans-trainer
[ 33%] Building CXX object CMakeFiles/kmeans-trainer.dir/kmeans_trainer.cpp.o
Linking CXX executable kmeans-trainer
[ 33%] Built target kmeans-trainer
Scanning dependencies of target make-test-background
[ 41%] Building CXX object CMakeFiles/make-test-background.dir/make_test_background_image.cpp.o
Linking CXX executable make-test-background
[ 41%] Built target make-test-background
Scanning dependencies of target manual-classifier
[ 50%] Building CXX object CMakeFiles/manual-classifier.dir/manual_classifier.cpp.o
Linking CXX executable manual-classifier
[ 50%] Built target manual-classifier
Scanning dependencies of target test-classifiers
[ 58%] Building CXX object CMakeFiles/test-classifiers.dir/test_classifiers.cpp.o
[ 66%] Building CXX object CMakeFiles/test-classifiers.dir/predict_common.cpp.o
Linking CXX executable test-classifiers
[ 66%] Built target test-classifiers
Scanning dependencies of target train-SVM-alone
[ 75%] Building CXX object CMakeFiles/train-SVM-alone.dir/train_SVM_alone.cpp.o
[ 83%] Building CXX object CMakeFiles/train-SVM-alone.dir/training_common.cpp.o
Linking CXX executable train-SVM-alone
[ 83%] Built target train-SVM-alone
Scanning dependencies of target train-bovw
[ 91%] Building CXX object CMakeFiles/train-bovw.dir/train_bovw.cpp.o
[100%] Building CXX object CMakeFiles/train-bovw.dir/training_common.cpp.o
Linking CXX executable train-bovw
[100%] Built target train-bovw

对我来说,在Windows上,当我打开文件编辑器(Atom)运行批处理脚本时,我收到了类似的错误消息。 不要以为原来的问题提到了操作系统,我确信我的问题是Windows特有的。

尽管操作系统是由代码示例中的URL隐含的。

如果它不是文件句柄/编辑器问题,它可能是一个fie权限错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM