Cmake not working in opencv c ++ project

I need your help! I have this C ++ code in this link

[link] https://github.com/royshil/FoodcamClassifier

and I have been trying for two days to internalize it and I have failed they say I should use cmake, I tried the "GUI version and it gave me errors that were implemented by cmake itself". so I took the cpp and headers files and made a new project, but now I have 100 errors related to the opencv library and I swear to god. I'm pretty sure it includes folders and their libraries in my project! I don't know what is connected with this!

any idea?

Here's the errors:

'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 '
+3


source to share


4 answers


You probably need to add the following piece of code at the CMakeLists.txt

before line FIND_PACKAGE(OpenCV Required)

(in my case):

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

      



In my installation, it solved the problem as the specified files are in the build folder.

+2


source


So this is what fixed it for me.

First, when in doubt, always remember to clear the CMake cache before trying to add some other path / value / mod . It seems a little odd that I know, but the legacy of previous attempts to fix the situation may take the true problem. The easiest way to do this is to cut from your original "build" directory from orbit (just to be sure) and try again ...

Second, and mostly, what is your target compiler and architecture here and what is provided by the version of the downloaded OpenCV? For example, at the time of writing, OpenCV 3.1, the pre-built installer I downloaded provides ~\build\x64\vc12 & vc14

- which of course were built against VisualStudio 2012 and 2014.

I used Mingw and targeting x86 - so I downloaded the source (via github release as a file *.zip

) and took these steps from the folder \opencv

:

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

      

Of course, you can manage the assembly of various switches and also determine where the installation should go.



Performing the "install" step - by default - copying final libraries, etc. to a folder named "install" is the key, as it correctly places all the resulting libraries and files in the right place and includes the magic OpenCVConfig.cmake

file at the top.

This way I could finally tell my CMakeLists.txt project to resolve OpenCV with

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

find_package( OpenCV REQUIRED )

      

And making sure the resulting executable knew about the * .dll with:

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

      

+1


source


On Linux I did the following:

$ 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

      

0


source


For me on Windows, I got a similar error message when I ran batch scripts with an open file editor (Atom). Don't assume the original question mentions OS and I'm pretty sure my problem is Windows related.

Although the OS is implied by the URL in the sample code.

If it's not a file descriptor / editor issue, it's probably a permissions error.

0


source







All Articles