Reputation: 1772
I have installed OpenCV using the instructions in https://help.ubuntu.com/community/OpenCV
$ sudo su
$ sudo apt-get install build-essential
$ sudo apt-get install libavformat-dev
$ sudo apt-get install ffmpeg
$ sudo apt-get install libcv2.3 libcvaux2.3 libhighgui2.3 python-opencv opencv-doc libcv-dev libcvaux-dev libhighgui-dev
now when i execute "pkg-config --cflags --libs opencv" i get this error:
Package opencv was not found in the pkg-config search path.
Perhaps you should add the directory containing `opencv.pc'
to the PKG_CONFIG_PATH environment variable
No package 'opencv' found
how can I resolve this problem?
-------UPDATE-------
OK, I figured out how to solve the problem...
I made a file named "opencv.pc" and copied it to "/usr/local/lib/pkgconfig" Then i added these two lines to ".bashrc":
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
that's it! everything is OK now.
the contents of the file are:
prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: opencv
Description: The opencv library
Version: 2.x.x
Cflags: -I${includedir}/opencv -I${includedir}/opencv2
Libs: -L${libdir} -lopencv_calib3d -lopencv_imgproc -lopencv_contrib -lopencv_legacy -lopencv_core -lopencv_ml -lopencv_features2d -lopencv_objdetect -lopencv_flann -lopencv_video -lopencv_highgui
UPDATE - 2014
it seems that the ubuntu community has completed the documentation on installing openCV, all you have to do now is to download the installation script from https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/opencv_latest.sh and execute it.
Upvotes: 84
Views: 208170
Reputation: 7146
From opencv 4.0:
add -DOPENCV_GENERATE_PKGCONFIG=YES
to cmake build arguments.
Use YES
, ON
is not working anymore.
Example:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-DWITH_V4L=ON \
-DWITH_LIBV4L=ON \
-DWITH_FFMPEG=ON \
-DOPENCV_GENERATE_PKGCONFIG=YES \
-D BUILD_EXAMPLES=ON ..
Upvotes: 2
Reputation: 510
git clone https://github.com/opencv/opencv.git
git clone https://github.com/opencv/opencv_contrib.git
cd opencv/
mkdir build
cd build/
#now Run cmake
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local ..
check detailed explanation here https://docs.opencv.org/3.4/d7/d9f/tutorial_linux_install.html
Upvotes: 0
Reputation: 39
Please try to set the environment in .bashrc:
tomapaxxx@localhost:~$ cat .bashrc
a)export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:~/workspace/usr/local/pkgconfig
export PYTHONPATH=/usr/bin/python2.7:$PYTHONPATH
b)After edition please find the file opencv.pc ,mkdir -p ~/workspace/usr/local/pkgconfig,then copy opencv.pc under the path ~/workspace/usr/local/pkgconfig.
d)source .bashrc under ~/. or ~/.bashrc.
eg: root@localhost:source ~/.bashrc
e)At the end you can use pkg-config --libs --cflags opencv to check whether you can see any information.
f)It is better if you can write information in .bash_profile with ./bashrc.
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
Upvotes: 0
Reputation: 316
Writing this answer specially for MacOS users.
First to install opencv use:
brew install opencv
or brew install opencv@x (x = 2,4)
We need to have the path of opencv.pc in the PKG_CONFIG_PATH to avoid this error. When you install opencv with brew it says something like this on console
For pkg-config to find opencv@2 you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv@2/lib/pkgconfig"
As the error suggest the reason is that opencv is not in the PKG_CONFIG_PATH variable. First check what is inside the variable using:
echo $PKG_CONFIG_PATH
To include the location of opencv.pc to the PKG_CONFIG_PATH use this
echo 'export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv/lib/pkgconfig:$PKG_CONFIG_PATH"' >> ~/.zshrc
Upvotes: 3
Reputation: 1
$ apt-file search opencv.pc $ ls /usr/local/lib/pkgconfig/ $ sudo cp /usr/local/lib/pkgconfig/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/opencv.pc $ pkg-config --modversion opencv
Upvotes: 0
Reputation: 31
I installed opencv following the steps on https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html
Except on Step 2, use: cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/path/to/opencv/ ..
Then locate the opencv4.pc file, mine was in opencv/build/unix-install/
Now run: $ export PKG_CONFIG_PATH=/path/to/the/file
Upvotes: 3
Reputation: 493
When you run cmake add the additional parameter -D OPENCV_GENERATE_PKGCONFIG=YES (this will generate opencv.pc file)
Then make and sudo make install as before.
Use the name opencv4 instead of just opencv Eg:-
pkg-config --modversion opencv4
Upvotes: 7
Reputation: 1480
with opencv 4.0;
-DOPENCV_GENERATE_PKGCONFIG=ON
to build argumentspkg-config --cflags --libs opencv4
instead of opencvUpvotes: 56
Reputation: 4395
I got the same error when trying to compile a Go package on Debian 9.8:
# pkg-config --cflags -- libssl libcrypto
Package libssl was not found in the pkg-config search path.
Perhaps you should add the directory containing `libssl.pc'
The thing is that pkg-config
searches for package meta-information in .pc
files. Such files come from the dev package. So, even though I had libssl
installed, I still got the error. It was resolved by running:
sudo apt-get install libssl-dev
Upvotes: 2
Reputation: 1
$ ./configure --enable-libopencv
ERROR: opencv not found using pkg-config
$ cat /usr/lib64/pkgconfig/opencv.pc
# Package Information for pkg-config
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib64
includedir_old=${prefix}/include/opencv
includedir_new=${prefix}/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 3.1.0
Libs: -L${exec_prefix}/lib64 -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cvv -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
Libs.private: -L/usr/lib64 -lQt5Test -lQt5Concurrent -lQt5OpenGL -L/lib64 -lwebp -lpng -ltiff -ljasper -ljpeg -lImath -lIlmImf -lIex -lHalf -lIlmThread -lgdal -lgstvideo-1.0 -lgstapp-1.0 -lgstbase-1.0 -lgstriff-1.0 -lgstpbutils-1.0 -lgstreamer-1.0 -lucil -lunicap -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lfontconfig -lfreetype -lglib-2.0 -ldc1394 -lv4l1 -lv4l2 -lgphoto2 -lgphoto2_port -lexif -lQt5Core -lQt5Gui -lQt5Widgets -lhdf5_hl -lhdf5 -lz -ldl -lm -ltesseract -llept -lpthread -lrt -lGLU -lGL
Cflags: -I${includedir_old} -I${includedir_new}
$ pkg-config --cflags --libs opencv
-I/usr/include/opencv -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_cvv -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_hdf -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core
$ uname -a
Linux fedora-23-x64 4.8.13-100.fc23.x86_64 #1 SMP Fri Dec 9 14:51:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
Upvotes: -1
Reputation: 1137
From your question I guess you are using Ubuntu (or a derivate). If you use:
apt-file search opencv.pc
then you see that you have to install libopencv-dev
.
After you do so, pkg-config --cflags opencv
and pkg-config --libs opencv
should work as expected.
Upvotes: 53
Reputation: 1772
it seems that the ubuntu community has completed the documentation on installing openCV,
so all you have to do now is to download the installation script from here and execute it.
don't forget to make it executable:
chmod +x opencv_latest.sh
then
./opencv_latest.sh
Upvotes: 6
Reputation: 450
Hi first of all i would like you to use 'Synaptic Package Manager'. You just need to goto the ubuntu software center and search for synaptic package manager.. The beauty of this is that all the packages you need are easily available here. Second it will automatically configures all your paths. Now install this then search for opencv packages over there if you found the package with the green box then its installed but else the package is not in the right place so you need to reinstall it but from package manager this time. If installed then you can do this only, you just need to fill the OpenCV_DIR variable with the path of opencv (containing the OpenCVConfig.cmake file)
export OpenCV_DIR=<path_of_opencv>
Upvotes: 2