gpt4 book ai didi

opencv - 如何设置包含路径#include “opencv2/opencv.hpp”

转载 作者:行者123 更新时间:2023-12-02 16:36:10 27 4
gpt4 key购买 nike

我正在尝试在此页面中使用OpenCV进行编译部分:Installing Darknet

完成OPENCV = 1后,我尝试进行重新制作,因此我在darknet目录中进行了make

目录在下面。

(yolo) bash-3.2$ pwd
/Users/moray/darknet
(yolo) bash-3.2$ ls
LICENSE LICENSE.gpl LICENSE.v1 backup data libdarknet.a python src
LICENSE.fuck LICENSE.meta Makefile cfg examples libdarknet.so results
LICENSE.gen LICENSE.mit README.md darknet include obj scripts

重新制作的结果就在这里。
(yolo) bash-3.2$ make
g++ -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -c ./src/image_opencv.cpp -o obj/image_opencv.o
/bin/sh: pkg-config: command not found
./src/image_opencv.cpp:6:10: fatal error: 'opencv2/opencv.hpp' file not found
#include "opencv2/opencv.hpp"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [obj/image_opencv.o] Error 1

所以我以为include路径不能引用 opencv.hpp,所以我寻找了文件并找到了它。
(yolo) bash-3.2$ ls ~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp
/Users/moray/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp

因此,我尝试将 #include "opencv2/opencv.hpp"中的 "include "~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp"更改为 ./src/image_opencv.cpp
结果就在这里。
(yolo) bash-3.2$ make
g++ -Iinclude/ -Isrc/ -DOPENCV `pkg-config --cflags opencv` -Wall -Wno-unused-result -Wno-unknown-pragmas -Wfatal-errors -fPIC -Ofast -DOPENCV -c ./src/image_opencv.cpp -o obj/image_opencv.o
/bin/sh: pkg-config: command not found
./src/image_opencv.cpp:7:10: fatal error:
'~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp' file not found
#include "~/opt/anaconda3/pkgs/libopencv-3.4.2-h7c891bd_1/include/opencv2/opencv.hpp"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [obj/image_opencv.o] Error 1

我不明白为什么会发生错误。
请告诉我您的想法。

===========================================

操作系统:macOS Catalina 10.15.1

(yolo)是anaconda中的虚拟环境(3)

opencv是通过(yolo)中的pip命令安装的

(yolo)中通过pip命令的所有软件包:
(yolo) bash-3.2$ pip list
Package Version
--------------------- -------------------
certifi 2019.11.28
numpy 1.17.4
opencv-contrib-python 4.1.2.30
opencv-python 4.1.1.26
pip 19.3.1
setuptools 42.0.2.post20191203
wheel 0.33.6

gcc:
(yolo) bash-3.2$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin19.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

最佳答案

此错误将其解释为pkg-config: command not found。为了在YOLO中使用OpenCV,您必须安装适用于 C或C++ 程序(而非Python)的OpenCV。您可能使用pip for Python安装了opencv。请按照以下任一链接中的步骤安装opencv:thisthis或其他教程。

之后,要检查您是否正确安装了OpenCV并可以在C程序中使用,请运行以下命令:

pkg-config --modversion opencv

如果没有显示任何内容或显示错误的版本,请尝试重新安装OpenCV ,这可能是您的计算机未正确找到opencv版本。
因此,将命令添加到 ~/.bashrc中,例如:
vim ~/.bashrc
export PKG_CONFIG_PATH=/home/user/installation/OpenCV-3.4.0/lib/pkgconfig
source ~/.bashrc

注意:根据包含 opencv.pc的opencv安装目录更改路径

关于opencv - 如何设置包含路径#include “opencv2/opencv.hpp”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59315993/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com