网站建设作业教程,邯郸网站设计定制,wordpress订单插件,柒零叁网温州论坛1、下载opencv 2、下载CMake 3、下载MinGW 放到一个文件夹中 并解压另外两个文件 4、cmake编译opencv 新建文件夹mingw-build 双击cmake-gui 程序会开始自动生成Makefiles等文件配置#xff0c;需要耐心等待一段时间。 简单总结下#xff1a;finish-configuring …1、下载opencv 2、下载CMake 3、下载MinGW 放到一个文件夹中 并解压另外两个文件 4、cmake编译opencv 新建文件夹mingw-build 双击cmake-gui 程序会开始自动生成Makefiles等文件配置需要耐心等待一段时间。 简单总结下finish-configuring done-configure-generate 5、安装 打开cmdcd至刚刚的构建目录下C:\Users\wuxulong\cpp_env_2\opencv\build\mingw-build 输入编译指令minGW32-make -j8完成后再输入minGW32-make install 也要等一段时间 6、配置环境变量
7、配置文件 c_cpp_properties.json
{configurations: [{name: Win32,includePath: [${workspaceFolder}/**,C:\\Users\\wuxulong\\cpp_env_2\\opencv\\build\\mingw-build\\install\\include,//修改这里C:\\Users\\wuxulong\\cpp_env_2\\opencv\\build\\mingw-build\\install\\include\\opencv2//修改这里// C:\\Users\\wuxulong\\cpp_env\\OpenCV-MinGW-Build-OpenCV-4.5.2-x64\\include\\opencv2\\core\\core.hpp// F:\\Tools\\opencv\\build\\include\\opencv ],defines: [_DEBUG,UNICODE,_UNICODE],windowsSdkVersion: 10.0.18362.0,compilerPath: C:\\Users\\wuxulong\\cpp_env_2\\mingw64\\bin\\g.exe,//修改这里cStandard: c11,//cStandard: c17,cppStandard: c17,intelliSenseMode: gcc-x64//intelliSenseMode: windows-gcc-x64//intelliSenseMode: ${default}}],version: 4
}lanuch.json
{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid830387version: 0.2.0,configurations: [{name: (gdb) Launch,preLaunchTask: g.exe build active file,//调试前执行的任务就是之前配置的tasks.json中的label字段type: cppdbg,//配置类型只能为cppdbgrequest: launch,//请求配置类型可以为launch启动或attach附加program: ${fileDirname}\\${fileBasenameNoExtension}.exe,//调试程序的路径名称args: [],//调试传递参数stopAtEntry: false,cwd: ${workspaceFolder},environment: [],externalConsole: false,//true显示外置的控制台窗口false显示内置终端MIMode: gdb,miDebuggerPath: C:\\Users\\wuxulong\\cpp_env_2\\mingw64\\bin\\gdb.exe,setupCommands: [{description: Enable pretty-printing for gdb,text: -enable-pretty-printing,ignoreFailures: true}]}]}tasks.json
{version: 2.0.0,tasks: [{type: cppbuild,label: g.exe build active file,command: C:\\Users\\wuxulong\\cpp_env_2\\mingw64\\bin\\g.exe,args: [-fdiagnostics-coloralways,-g,// -stdc11,${file},//E:\\Git-resp\\C\\yolov8_CPP_Inference_OpenCV_ONNX\\inference.cpp,-o,${fileDirname}\\${fileBasenameNoExtension}.exe,//-I,E:\\Git-resp\\C\\yolov8_CPP_Inference_OpenCV_ONNX,-I,C:\\Users\\wuxulong\\cpp_env_2\\opencv\\build\\mingw-build\\install\\include,-I,C:\\Users\\wuxulong\\cpp_env_2\\opencv\\build\\mingw-build\\install\\include\\opencv2,-L,C:\\Users\\wuxulong\\cpp_env_2\\opencv\\build\\mingw-build\\install\\x64\\mingw\\bin\\lib*],options: {cwd: C:\\Users\\wuxulong\\cpp_env_2\\mingw64\\bin},problemMatcher: [$gcc],group: {kind: build,isDefault: true//表示快捷键CtrlShiftB可以运行该任务},// group: build,detail: 编译器: C:\\Users\\wuxulong\\cpp_env_2\\mingw64\\bin\\g.exe}]
}main.cpp
/*********************** 显示指定地址的图片*****************************/#includeiostream
#includeopencv2/opencv.hpp
#include unistd.h
// #includeopencv2/core/core.hpp
// #includeopencv2/highgui/highgui.hpp
using namespace std;
using namespace cv;int main(int argc, char** argv) { Mat image;image imread(data/image/2.jpg);if (image.data nullptr) //nullptr是c11新出现的空指针常量{cout 图片文件不存在 endl;}else{//显示图片imshow(meinv, image);waitKey(0);}// 输出图片的基本信息cout 图像宽为 image.cols \t高度为 image.rows \t通道数为 image.channels() endl;sleep(10);// 遍历每个像素//之所以用y这个名字表示行 是因为图片的坐标系中行号就是yfor (int y 0; y image.rows; y){unsigned char* row_ptr image.ptrunsigned char(y);for (int x 0; x image.cols; x) {//这是获得像素数据数组的头指针注意像素数据可能会有多个通道所以才需要用数组存储unsigned char* data_ptr row_ptr[x * image.channels()];//对当前像素逐个通道输出颜色值for (int i 0; i image.channels(); i) {cout int(data_ptr[i])endl;}}}// system(pause);return 0;
}结果
参考2023年最全 Windows VSCode 配置 OpenCV C 一站式开发调试环境教程