Thursday, September 28, 2017

[C#] OpenCvSharp Detect Object in Image by Contour | OpenCvSharp 使用輪廓偵測圖片中的物體

snip_20170928110929

This time I will try to detect objects from image by OpenCvSharp, let me introduce the flow first.
這次我要用OpenCvSharp嘗試偵測圖片中的物體,讓我先介紹流程。

  1. Load image (I load image as gray scale here). | 讀取圖片(我直接讀成灰階)
  2. Blur the image (I choose Gaussian Blur). | 模糊化圖片(我用高斯模糊)
  3. Get edge (use canny) | 取得邊緣(使用Canny)
  4. Find the Contour. | 找出輪廓
  5. Get right contour and draw on image. | 取得正確的輪廓並畫到圖片上上

Tuesday, September 19, 2017

[C#] OpenCvSharp Draw Histogram | OpenCvSharp 畫直方圖

最近我使用OpenCv做研究,發現C#在這領域蠻缺乏資源的,在找怎麼畫出直方圖時花了一些時間,所以現在來分享一下結果。
Recently I was using OpenCV to do research, found C# in this field was quite lack of resources, looking for how to draw the histogram took me some time, so now to share the results.

首先,使用nuget安裝OpenCvSharp,目前C#比較好用的OpenCv Wrapper。
First, use nuget to install OpenCvSharp, the current better OpenCv Wrapper for C#.

HistExample1


然後參考下列程式碼
Then refer to the following code

Thursday, September 7, 2017

Merge DLL into EXE on WPF via LibZ | 使用LibZ在WPF上將DLL合併至EXE內

In winform, you can use ILMerge merge DLLs into EXE, but it can't work on WPF, so we need find another way to do it. Lot of people recommend this post "Combining multiple assemblies into a single EXE for a WPF application", but it didn't work on me, luckily I found another way to do it.
在winform上,你可以用ILMerge合併DLLs到EXE裡,但是在WPF上沒辦法辦到,所以我們需要找另外的方法來達成。很多人推薦這篇" Combining multiple assemblies into a single EXE for a WPF application "的方式,但是在我的情況不適用,還好我找到另外的方式。


Using LibZ, we can use commend line doing merge like using ILMerge, you can even use LibZ as library to control it in code for advanced use. For me, Libz can merge DLLs into EXE on WPF, it saved my day.
使用LibZ,我們可以跟ILMerge一樣用指令列來做合併,在進階的狀況,甚至可以在程式內呼叫LibZ library來使用他。對我來說,LibZ可以在WPF上將DLLs合併至EXE內,這省了我很多時間。


LibZ github nuget


To use LibZ is easy, the fast way for me is use NuGet Package Manager Console (in Visual Studio -> Tools -> NuGet Package Manager -> Package Manager Console)
使用LibZ很簡單,最快的方式就是使用NuGet Package Manager Console (在Visual Studio中-> Tools -> NuGet Package Manager -> Package Manager Console)


Open NuGet Package Manager Console, type in following commend to install
開啟NuGet Package Manager Console,輸入下列指令安裝
PM>Install-Package LibZ.Tool -Version 1.2.0
libz1


After LibZ.Tool package installed, goto the dictionary that having you want to merge's file, using following commend to merge DLLs into EXE.
LibZ.Tool安裝完後,到有你要合併的檔案之目錄,使用下列指令來將DLLs合併至EXE.

PM>libz inject-dll --assembly .\YOUREXE.exe --include .\YOURDLL.dll
libz2


Then it's done.
然後就完成啦。


You can read LibZ document to get more help.
你可以閱讀LibZ的文件來取得更多幫助。