Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu OpenCV not compiling

Tags:

c++

opencv

ubuntu

I'm trying to compile OpenCV 3.2 with contributions with the following commands:

1.
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX=/usr/local/ -DOPENCV_EXTRA_MODULES_PATH=/home/matteo/Desktop/Xilinx/OpenCV/source/opencv_contrib/modules/ /home/matteo/Desktop/Xilinx/OpenCV/source/opencv-3.2.0/
2.
make -j7 # runs 7 jobs in parallel
3.
sudo make install

Can you explain why I get

...
........
...........
........................
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Caffe:   NO
-- Protobuf:   NO
-- Glog:   NO
-- Downloading ...
CMake Error at cmake/OpenCVUtils.cmake:1043 (file):
  file DOWNLOAD cannot open file for write.
Call Stack (most recent call first):
  ../opencv_contrib/modules/dnn/cmake/OpenCVFindLibProtobuf.cmake:32 (ocv_download)
  ../opencv_contrib/modules/dnn/CMakeLists.txt:5 (include)


CMake Error at cmake/OpenCVUtils.cmake:1047 (message):
  Failed to download .  Status=
Call Stack (most recent call first):
  ../opencv_contrib/modules/dnn/cmake/OpenCVFindLibProtobuf.cmake:32 (ocv_download)
  ../opencv_contrib/modules/dnn/CMakeLists.txt:5 (include)


-- Configuring incomplete, errors occurred!

I'm working with Ubuntu 16.04 . I already had OpenCV on the system: maybe I unistall it in the wrong way? I remember to compile OpenCV 3.2 with the same command used above.

like image 811
user1315621 Avatar asked Mar 28 '17 22:03

user1315621


People also ask

Does OpenCV work on Ubuntu?

OpenCV-Python can be installed in Ubuntu in two ways: Install from pre-built binaries available in Ubuntu repositories. Compile from the source.

Where is OpenCV path in Ubuntu?

You can find OpenCV2 (i.e. C++ version) libraries (e.g. libopencv_core.so,libopencv_highgui.so etc) at /usr/local/lib . If you want libraries for c version only (e.g. libcv. a,libcxcore. a etc) you can find them at /usr/lib .


4 Answers

You must have matching versions of the opencv_contrib and the opencv itself.

Under the opencv github, go to the OpenCV releases and download the 3.2.0 (it should be the same in the master branch).

Now, go to https://github.com/opencv/opencv_contrib/releases and download the 3.2.0. Then you will have both versions matching.

After that all the cmake commands found on the README.md at opencv_contrib master branch should work fine.

like image 67
Miguel Rocha Jr. Avatar answered Oct 21 '22 05:10

Miguel Rocha Jr.


I get the same error, that exact error, around the protobuf. There's another error on the xfeatures2d module, too, if your delete the dnn modules (so they don't get configured/built). My problem is, I need the "non-free" xfeatures2d module. :(

The problem appears to be in the opencv_contrib, in the DNN and xfeatures2d modules, but I'm not sure how to fix it. the call to ocv_download seems to be having empty inputs, even though the dnn and xfeatures2d cmake files are passing in arguments. I am not even a novice with cmake, so I'm not sure how to troubleshoot further.

I get this error on both Mac configuring for XCode and on Windows configuring for Visual Studio, using the latest version of cmake-gui, 3.8.0-rc3.


EDIT: I think I've found the issue, though. I opened an issue in the opencv_contrib github. There is a call to ocv_download in the dnn and xfeatures2d cmake files that uses FILENAME as the first parameter, but should be using PACKAGE instead. When I changed the parameters to PACKAGE, CMake successfully configured opencv with the opencv_contrib modules.

Hope this helps! :)

like image 33
Matt Avatar answered Oct 21 '22 06:10

Matt


You might not use the same version of opencv and opencv_contrib

https://github.com/opencv/opencv_contrib/archive/<version>.zip https://github.com/opencv/opencv/archive/<version>.zip

like master or 3.2.0

like image 38
Ken Lee Avatar answered Oct 21 '22 05:10

Ken Lee


SHORT

You need to have the same version in opencv and opencv_contrib (.../opencv_contrib/modules/... belongs to an independent repo).

Either the same release or the last commit in BOTH repositories.

Check which version you have and move the other. In your case, I guess you have to change the version of opencv_contrib, then move to the release with git or download it from github.

git checkout <number_opencv_version i.e. 3.2.0>

LONG

I guess as Ken Lee, that you do not have the same version in the repositories.

As Matt referenced in the opened issue, there is a problem with the call of ocv_download because the version is not the one that was used when opencv-3.1, therefore it fails because the parameter is not the expected one.

It happens to me when I was using opencv 3.1.0 and the last version of opencv_contrib. You could change the cmake files one by one, but it is easier to take the correct version in each repo.

like image 28
MarcosBernal Avatar answered Oct 21 '22 05:10

MarcosBernal