我已经按照 https://help.ubuntu.com/community/OpenCV 中的说明安装了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
现在,当我执行"pkg-config --cflags --libs opencv"时,我收到此错误:
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
如何解决此问题?
-------更新-------
好的,我想出了解决问题的方法...
我制作了一个名为"opencv.pc"的文件,并将其复制到"/usr/local/lib/pkgconfig"然后我在".bashrc"中添加了这两行:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
就是这样!现在一切都好了。
该文件的内容是:
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
更新 - 2014
看来 Ubuntu 社区已经完成了安装 OpenCV 的文档,您现在要做的就是从 https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/opencv_latest.sh 下载安装脚本并执行它。
从你的问题中,我猜你使用的是 Ubuntu(或衍生产品(。如果您使用:
apt-file search opencv.pc
然后你看到你必须安装libopencv-dev
.
执行此操作后,pkg-config --cflags opencv
和pkg-config --libs opencv
应按预期工作。
with opencv 4.0;
- 添加
-DOPENCV_GENERATE_PKGCONFIG=ON
以生成参数 -
pkg-config --cflags --libs opencv4
而不是OpenCV
当你运行cmake时,添加额外的参数-D OPENCV_GENERATE_PKGCONFIG=YES(这将生成opencv.PC文件(
然后像以前一样制作和 sudo 进行安装。
使用名称 opencv4 而不仅仅是 opencv 例如:-
pkg-config --modversion opencv4
似乎 ubuntu 社区已经完成了安装 openCV 的文档,
因此,您现在要做的就是从此处下载安装脚本并执行它。
不要忘记使其可执行:
chmod +x opencv_latest.sh
然后
./opencv_latest.sh
我按照 https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html 的步骤安装了opencv
除步骤 2 外,请使用:cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=YES -D CMAKE_INSTALL_PREFIX=/path/to/opencv/..
然后找到opencv4.pc文件,我的在opencv/build/unix-install/
现在运行:$ export PKG_CONFIG_PATH=/path/to/the/file
首先,我希望您使用"突击包管理器"。你只需要去 ubuntu 软件中心并搜索突触包管理器。这样做的美妙之处在于,您需要的所有软件包都可以在这里轻松获得。其次,它将自动配置您的所有路径。现在安装它,然后在那里搜索opencv软件包,如果你找到带有绿色框的软件包,那么它已安装,否则软件包不在正确的位置,所以你需要重新安装它,但这次从包管理器。如果已安装,那么您只能执行此操作,您只需要使用opencv的路径填充OpenCV_DIR变量(包含OpenCVConfig.cmake文件(
export OpenCV_DIR=<path_of_opencv>
Debian 9.8 上编译 Go 软件包时遇到了同样的错误:
# 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'
问题是pkg-config
在.pc
文件中搜索包元信息。此类文件来自开发包。因此,即使我安装了libssl
,我仍然收到错误。已通过运行以下命令解决:
sudo apt-get install libssl-dev
专门为MacOS用户编写此答案。
首先安装 opencv 使用:
brew install opencv
or brew install opencv@x (x = 2,4)
我们需要在PKG_CONFIG_PATH中拥有opencv.pc的路径以避免此错误。当您使用 brew 安装 opencv 时,它会在控制台上显示如下内容
For pkg-config to find opencv@2 you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv@2/lib/pkgconfig"
正如错误所暗示的那样,原因是 opencv 不在 PKG_CONFIG_PATH 变量中。首先使用以下命令检查变量内部的内容:
echo $PKG_CONFIG_PATH
要将opencv.pc的位置包含在PKG_CONFIG_PATH请使用此
echo 'export PKG_CONFIG_PATH="/opt/homebrew/opt/opencv/lib/pkgconfig:$PKG_CONFIG_PATH"' >> ~/.zshrc
从opencv 4.0开始:
将-DOPENCV_GENERATE_PKGCONFIG=YES
添加到 CMAKE 构建参数。
使用 YES
,ON
不再工作。
例:
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 ..
$ 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
请尝试在 .bashrc 中设置环境:
tomapaxxx@localhost:~$ 猫 .bashrc
a(export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:~/workspace/usr/local/pkgconfig
export PYTHONPATH=/usr/bin/python2.7:$PYTHONPATH
b(编辑后,请找到文件 opencv.pc ,mkdir -p ~/workspace/usr/local/pkgconfig,然后在路径 ~/workspace/usr/local/pkgconfig 下复制 opencv.pc。
d(来源 .bashrc 下 ~/.或 ~/.bashrc。
例如:root@localhost:source ~/.bashrc
e(最后你可以使用 pkg-config --libs --cflags opencv 来检查你是否可以看到任何信息。
f(如果您可以使用 ./bashrc 以 .bash_profile 编写信息,那就更好了。
如果 [ -f ~/.bashrc ];然后
.~/.巴什尔克
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
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 ..
在此处查看详细说明https://docs.opencv.org/3.4/d7/d9f/tutorial_linux_install.html
$ ./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