vscode c++ code runner 配置 opencv

参考链接:
【OpenCV4】Mac 系统下使用 vscode 配置 c++ 版 OpenCV4.5.4 成功
在参考该博主的博客后,一般情况下使用vscode编写c++使用opencv能够成功,但我遇到的的问题是编译的过程找不到头文件。

fatal error: 'opencv2/core.hpp' file not found

这个时候就与编译的参数设置有关,由于我使用的是code runner,最后将cpp的编译参数修改为如下即可。

"cpp": "cd $dir && g++ -std=c++11 `pkg-config --cflags --libs opencv4` $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",

最关键的参数就是这个。

pkg-config --cflags --libs opencv4

如果不出意外的话,还是会出意外滴~
当你执行这个命令的时候需要出现如下代码,才会是正常情况。

-I/usr/local/opt/opencv/include/opencv4 -L/usr/local/opt/opencv/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_barcode -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_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_dnn -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core

这个时候在网上搜索到的博客,大部分是教你如何手动去配置opencv4.pc文件,需要根据自己opencv的安装路径去进行配置,比较复杂而且我是没有成功的。
正当我万念俱灰准备使用brew重新安装opencv的时候,提示我由于opencv已经安装,只需执行如下命令即可。

brew link opencv

执行完成后,成功work了,可自动帮你创建opencv4.pc文件,大功告成!

opencv 学习

string type2str(int type) {
    string r;
    uchar depth = type & CV_MAT_DEPTH_MASK;
    uchar chans = 1 + (type >> CV_CN_SHIFT);
    switch ( depth ) {
        case CV_8U:  r = "8U"  ; break;
        case CV_8S:  r = "8S"  ; break;
        case CV_16U: r = "16U" ; break;
        case CV_16S: r = "16S" ; break;
        case CV_32S: r = "32S" ; break;
        case CV_32F: r = "32F" ; break;
        case CV_64F: r = "64F" ; break;
        default:     r = "User"; break;
    }
    r += "C";
    r += (chans+'0');
    return r;
}
// Value  C1 C2 C3 C4 C5 C6 C7 C8
// ====== == == == == == == == ==
// CV_8U   0  8 16 24 32 40 48 56
// CV_8S   1  9 17 25 33 41 49 57
// CV_16U  2 10 18 26 34 42 50 58
// CV_16S  3 11 19 27 35 43 51 59
// CV_32S  4 12 20 28 36 44 52 60
// CV_32F  5 13 21 29 37 45 53 61
// CV_64F  6 14 22 30 38 46 54 62

你可能感兴趣的:(vscode,c++,opencv)