步驟大致參考此,另外註記心得
https://github.com/shimat/opencvsharp/tree/master
OpenCVSharp只是opencv的C# wrapper,所以本機上必須要有opencv套件+opencvsharp
,需要特別注意版本對應問題,本篇針對opencv4.0.0做紀錄
https://github.com/shimat/opencvsharp/tree/master
OpenCVSharp只是opencv的C# wrapper,所以本機上必須要有opencv套件+opencvsharp
,需要特別注意版本對應問題,本篇針對opencv4.0.0做紀錄
- 安裝opencv原生套件庫+延伸模組
- github下載opencv原始碼
- /Users/Apple/Github/opencv_contrib
- 路徑例
- /Users/Apple/Github/opencv
- github下載opencv延伸模組
- https://github.com/opencv/opencv_contrib
- 路徑例
- /Users/Apple/Github/opencv_contrib
- 此時此刻是以master分支為準
- 不穩定的4.0?還沒搞懂但可以建置
- 編譯/安裝opencv原生套件庫
- 在 /Users/Apple/Github/opencv 下建立build資料夾
- opencv的cmake規則不允許/建議你在原始碼下直接建置
- 在build資料夾下開始cmake
- #cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
- 連同延伸模組一起建置
- cmake生成了Makefile,開始make
- #make -j5
- make完成後,安裝到/usr/local
- #sudo make install
- 編譯/安裝opencvsharp
- github下載opencvsharp原始碼
- https://github.com/shimat/opencvsharp/tree/master
- 路徑例
- Users/Apple/Github/opencvsharp/src
- 切換到tag4.0.0(用現在的master會一直鬼打牆
- 我是用source tree去切換的...
- cmake..
- cmake -D CMAKE_INSTALL_PREFIX=/usr/local
- 然後make..
- #make install..
- 會裝在/usr/local/lib/libOpenCvSharpExtern.dylib
- 用vscode+.net core 2.0測試
- 開.net core專案/初始化工作區
- #dotnet new console
- #dotnet add package OpenCvSharp3-WithoutDll
- 關鍵一步,WithoutDll
- build/lanuch
- 用opencvsharp的範例程式
// Edge detection by Canny algorithm using OpenCvSharp; class Program { static void Main() { Mat src = new Mat("lenna.png", ImreadModes.Grayscale); // Mat src = Cv2.ImRead("lenna.png", ImreadModes.Grayscale); Mat dst = new Mat(); Cv2.Canny(src, dst, 50, 200); using (new Window("src image", src)) using (new Window("dst image", dst)) { Cv2.WaitKey(); } } }
- 完成
學習心得:有點搞懂cmake,make,make install/uninstal的使用慣例,macOS透過dmg/直接make install/brew所安裝位置的差別(make install裝在/usr/local,brew裝在/usr/local/Cellar),以及cmake概念與套件庫搜尋位置,最重要的是...去看一下各套件tag的版本
沒有留言:
張貼留言