Ubuntu系統(tǒng)下如何在VScode配置OpenCV(C++)環(huán)境(.json文件)
更新時間:2025年02月12日 08:42:03 作者:forever0007
這篇文章主要介紹了如何在VSCode中配置和運行C++程序,包括創(chuàng)建test.cpp文件、配置launch.json、tasks.json和c_cpp_properties.json文件,以及重啟VSCode以解決可能的報錯問題,需要的朋友可以參考下
創(chuàng)建一個test文件,用VScode打開
(1)按住ctrl+shift+P搜索launch.json,點擊打開即可
(2)按住ctrl+shift+P 打開第一個
(1)、launch.json文件的配置
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++ - Build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", //程序文件路徑 "args": [], //程序運行需傳入的參數(shù) "stopAtEntry": false, "cwd": "${fileDirname}", "environment": [], "externalConsole": false, //運行時是否顯示控制臺窗口 "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "C/C++: g++ build active file", "miDebuggerPath": "/usr/bin/gdb" } ] }
(2)、tasks.json文件
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: g++ build active file", /* 與launch.json文件里的preLaunchTask的內(nèi)容保持一致 */ "command": "/usr/bin/g++", "args": [ "-std=c++11", "-g", //"${file}", /* 編譯單個文件 */ "${fileDirname}/*.cpp", /* 編譯多個文件 */ "-o", "${fileDirname}/${fileBasenameNoExtension}", /* 輸出文件路徑 */ /* 項目所需的頭文件路徑 */ "-I", "${workspaceFolder}/", "-I", "/usr/local/include/", "-I", "/usr/local/include/opencv4/", "-I", "/usr/local/include/opencv4/opencv2", /* 項目所需的庫文件路徑 */ "-L", "/usr/local/lib", /* OpenCV的lib庫 */ "/usr/local/lib/libopencv_*" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }
(3)、c_cpp_properties.json文件
{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "/usr/local/include/opencv4", "/usr/include/**" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "gnu11", "cppStandard": "gnu++14", "intelliSenseMode": "linux-gcc-x64", "configurationProvider": "ms-vscode.makefile-tools" } ], "version": 4 }
(4)、測試
創(chuàng)建一個test.cpp文件,輸入測試代碼
#include <opencv2/opencv.hpp> #include <string> #include <iostream> using namespace std; int main(int argc, char* argv[]) { string Path = "test.jpg";//此處為的圖片路徑 //從文件中讀入圖像 cv::Mat img = cv::imread(Path, 1); //如果讀入圖像失敗 if (img.empty()) { cout<< "Not Found image"<<endl; return -1; } cv::imshow("image", img); //顯示圖像 cv::waitKey(); return 0; }
圖片顯示成功,配置完成?。ㄈ舫晒\行仍有報錯顯示,重啟VScode即可)
總結(jié)
到此這篇關(guān)于Ubuntu系統(tǒng)下如何在VScode配置OpenCV(C++)環(huán)境(.json文件)的文章就介紹到這了,更多相關(guān)Ubuntu VScode配置OpenCV環(huán)境內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C語言中單鏈表的基本操作(創(chuàng)建、銷毀、增刪查改等)
這篇文章主要介紹了C語言中單鏈表的基本操作(創(chuàng)建、銷毀、增刪查改等),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-02-02QT利用QPdfWriter實現(xiàn)繪制PDF(支持表單輸出)
這篇文章主要為大家詳細介紹了QT如何利用QPdfWriter實現(xiàn)繪制PDF,并可以支持表單輸出。文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下2023-01-01C++代碼和可執(zhí)行程序在x86和arm上的區(qū)別介紹
這篇文章主要介紹了C++代碼和可執(zhí)行程序在x86和arm上的區(qū)別,X86和ARM是占據(jù)CPU市場的兩大處理器,各有優(yōu)劣,本文給大家詳細介紹了兩者的區(qū)別,需要的朋友可以參考下2022-07-07