建置VScode的C++及OpenCV環境 by076
不需要OpenCV,相關OpenCV步驟可以不用做
Step 1: 下載VScode Windows x64 Stable
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Step 2: 下載Mingw64
Step 3: 下載OpenCV
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Hint : 下載完請解壓縮資料夾們,不要耍蠢:D
Step4: 建置環境變數
在搜尋欄搜尋編輯系統環境變數➜ 環境變數 ➜ 系統變數 ➜ Double click Path ➜ 新增 Mingw的bin路徑 ➜ 新增OpenCV的bin路徑
-
在搜尋欄搜尋編輯系統環境變數
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
環境變數
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
系統變數
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
Double click Path
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
新增 Mingw的bin路徑
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
新增OpenCV的bin路徑
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Step5: 把OpenCV裡的include和lib分別複製到mingw64中的include和lib
範例:
D:\APP\Opencv\build\include內的 "opencv2文件"複製到 D:\APP\Mingw\mingw64\include中
範例:
D:\APP\Opencv\build\lib 內的 "全部資料"複製到 D:\APP\Mingw\mingw64\lib中
Step6: 建置一個資料夾並建立test.cpp,在資料夾中右鍵"以Code開啟"
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Step7: 點開test.cpp,貼上範例程式
- include出現紅線先呼略啦
- test.png記得準備啦
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Hint: 終端機的開法
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Step8: 測試時間
-
先編譯一次檢查C++環境裝好了無
-
shift+ctrl+B ➜ 選擇g++編譯器
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
若無先編譯,會出現這個問題
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
-
打在終端機上
g++ -g test.cpp -I D:\\APP\\Mingw\\mingw64\\include -lopencv_core452 -lopencv_imgcodecs452 -lopencv_imgproc452 -lopencv_calib3d452 -lopencv_dnn452 -lopencv_features2d452 -lopencv_flann452 -lopencv_gapi452 -lopencv_highgui452 -lopencv_ml452 -lopencv_objdetect452 -lopencv_photo452 -lopencv_stitching452 -lopencv_video452 -lopencv_videoio452 -o test.exe
紅色的地方改成自己mingw64 include路徑
Step9: 執行資料夾內生成的test.exe
Step10: 在Coding用資料夾內建立名為.vscode的資料夾,在裡面新增tasks.json
Step11: 撰寫tasks.json
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Step12: 存檔後到test.cpp執行結果,有以下兩種方式:
1. Shift+ctrl+B : 只編譯出exe檔,要再手動執行exe。
2.
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
案下去就會編譯加執行exe啦!!
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Hint: 若出現此現象,則選擇g++編譯器
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
<補充>: 出現紅線 (ex: include出現紅線) 的解決辦法
1. 使用shift+ctrl+P叫出搜尋欄,輸入C++ config

2. 修改內文
