2012-05-12 14 views
0

沒有人有一個如何在C#中使用OpenCV進行鏤空的例子。在c#中使用OpenCV進行鏤空

謝謝

+1

-1。谷歌會幫助你解決這類問題。預計這裏的問題將包括一些研究工作。你有什麼嘗試?你面臨的問題是什麼? –

回答

2

我很抱歉,我沒有例如,從C#。但我可以給你一個使用OpenCV-Python的方法。它使用基本的OpenCV函數完成,所以我使用的所有函數都應該可以在C#中使用。

import cv2 
import numpy as np 

img = cv2.imread('img.png',0) 
size = np.size(img) 
skeleton = np.zeros(img.shape,np.uint8) 

ret,img = cv2.threshold(img,127,255,0) 
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3)) 
finished = False 

while(not finished): 
    eroded = cv2.erode(img,kernel) 
    temp = cv2.dilate(eroded,kernel) 
    temp = cv2.subtract(img,temp) 
    skel = cv2.bitwise_or(skeleton,temp) 
    img = eroded.copy() 

    zeros = size - cv2.countNonZero(img) 
    if zeros==size: 
     finished = True 

cv2.imshow("skeleton",skeleton) 
cv2.waitKey(0) 
cv2.destroyAllWindows() 

下面是結果:

enter image description hereenter image description here

方法也不是那麼好,所以也造成不完美。但更好,我希望。

EmguCV文檔:http://www.emgu.com/wiki/files/2.3.0/document/Index.html

我相信所有的功能均可在此處找到。所以實施你自己。