简体   繁体   English

无法找到 OpenCV header,但 pkg-config 包含路径

[英]Unable to locate OpenCV header, but pkg-config contains path

In order to install OpenCV on my Mac, I opted to use brew install opencv instead of building from source as is specified in the Mac installation tutorials.为了在我的 Mac 上安装 OpenCV,我选择使用brew install opencv代替 Mac 安装教程中指定的从源代码构建。 Homebrew's installation path appears to be /opt/homebrew, and all of the included packages that I have downloaded appear to be contained in the include in that directory. Homebrew 的安装路径似乎是 /opt/homebrew,而我下载的所有包含的包似乎都包含在该目录的 include 中。

I wrote a sample program program in order to test the installation:我编写了一个示例程序程序来测试安装:

#include <opencv4/opencv2/imgcodecs.hpp>
#include <opencv4/opencv2/highgui.hpp>
#include <opencv4/opencv2/imgproc.hpp>
#include <iostream>

using namespace std;
using namespace cv;

int main() {
    VideoCapture cap(0);
    Mat img;
    
    while (1) {
        cap.read(img);
        imshow("Image", img);
        
        if (waitKey(1) == 27) {
            break;
        }
    }

    return 0;
}

And, to compile it, I ran:而且,为了编译它,我运行了:

g++ video.cpp `pkg-config --cflags --libs opencv4`

which returned:返回:

fatal error: 'opencv4/opencv2/imgcodecs.hpp' file not found

I ran pkg-config --cflags --libs opencv4 to check whether it was set correctly, and the following was returned:我运行pkg-config --cflags --libs opencv4来检查它是否设置正确,并返回以下内容:

-I/opt/homebrew/Cellar/opencv/4.5.2_4/include/opencv4 -L/opt/homebrew/Cellar/opencv/4.5.2_4/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_viz -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_dnn -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core

I think that this implies that the path to OpenCV is set for linking the package during compilation, so I was wondering about why the linker couldn't find it.我认为这意味着 OpenCV 的路径设置为在编译期间链接 package,所以我想知道为什么 linker 找不到它。 Also, my end-goal is to write a program involving pcl, and I also installed pcl via brew.另外,我的最终目标是编写一个涉及 pcl 的程序,并且我还通过 brew 安装了 pcl。 Since it is also contained in opt/homebrew/, do I have to create a specific reference to its path outside of /usr/ when making the cake file?由于它也包含在 opt/homebrew/ 中,所以在制作蛋糕文件时是否必须在 /usr/ 之外创建对其路径的特定引用? Thanks!谢谢!

Thank you @Alan Birtles.谢谢@Alan Birtles。 It was just a problem with my includes.这只是我的包含问题。 For those reading, #include <opencv4/opencv2/imgcodecs.hpp> , as well as all of the other OpenCV packages, had to refer directly to OpenCV2.对于那些阅读, #include <opencv4/opencv2/imgcodecs.hpp> ,以及所有其他 OpenCV 包,必须直接参考 OpenCV2。 So, for example, it had to be #include <opencv2/imgcodecs.hpp>因此,例如,它必须是#include <opencv2/imgcodecs.hpp>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM