I’m installing opencv in ubuntu 16.04. After installing the necessary prerequisites I used the following command:-
kvs@Hunter:~/opencv_contrib$ mkdir build kvs@Hunter:~/opencv_contrib$ cd build kvs@Hunter:~/opencv_contrib/build$ kvs@Hunter:~/opencv_contrib/build$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX+/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
but it produced an error:-
CMake Error: The source directory "/home/kvs/opencv_contrib" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI.
I used the command provided in the folder ‘module’ documentation. How do I solve it?
I tried the answers here at stack-overflow and a few other question but still can’t figure it out.
Project Git repository here.
You should do
mkdir build and
cd build while inside
opencv folder, not the
opencv-contrib folder. The
CMakeLists.txt is there.
Since you add
.. after cmake, it will jump up and up (just like
cd ..) in the directory. But if you want to run cmake under the same folder with CMakeLists.txt, please use
. instead of
Follow the below steps (assuming you are building it using CMake GUI)
Download OpenCV (from here) and unzip it somewhere on your computer. Create a build folder inside it
Download extra modules from OpenCV (from here). Ensure you download the same version.
Unzip the folder.
Click Browse Source and navigate to your OpenCV folder.
Click Browse Build and navigate to your build folder.
Click the configure button. You will be asked how you would like to generate the files. Choose Unix-Makefile from the drop-down menu and Click OK. CMake will perform some tests and return a set of red boxes that appear in the CMake Window.
Search for "OPENCV_EXTRA_MODULES_PATH" and provide the path to the modules folder (e.g. /Users/purushottam_d/Programs/OpenCV3_4_5_contrib/modules)
Click Configure again, then Click Generate.
Go to the build folder
# cd build # make # sudo make install
An easier way to build OpenCV from source in a step by step fashion as given in this reference: Installing OpenCV from the Source
step 1: install dependencies,
sudo apt install build-essential cmake git pkg-config libgtk- 3-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev gfortran openexr libatlas-base- dev python3-dev python3-numpy libtbb2 libtbb-dev libdc1394-22-dev
Step 2: create a directory opencv_build and Clone the necessary repositories as shown below,
mkdir ~/opencv_build && cd ~/opencv_build git clone https://github.com/opencv/opencv.git git clone https://github.com/opencv/opencv_contrib.git
step 3: cd into opencv directory, inside create another directory called build and cd into it,
cd ~/opencv_build/opencv mkdir build && cd build
step 4: evoke Cmake to build OpenCV,
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_build/opencv_contrib/modules -D BUILD_EXAMPLES=ON ..
If step 4 completes successfully you should see the following line at the end of the terminal, the build has been written to the directory created in step 3, along with the following lines above this line,
step 5: To start the compilation process where -j
is a flag for the number of the processor inside your machine, for example -j6 means we have 6 processors available. to verify the number of processors type nproc on the terminal then use this number after -j. To start this process, we use the following command:
step 6: install OpenCV, We use,
sudo make install
then check the version Of OpenCV to verify the installation:
pkg-config --modversion opencv4
I had a similar problem with another package and neither operating from a clean directory, to build from out, nor copy/paste the CMakeLists.txt file from the source to the clean directory worked.
I simply solved installing by conda