2017-02-15 42 views
0

我能夠檢測關鍵點和描述符OpenCV的 - 只畫出對象是關鍵點是指使用python

keypoints, des = surf.detectAndCompute(gray_image,None) 

我能得出的關鍵點

output_image = cv2.drawKeypoints(output_image, keypoints) 

我能找到下圖中的關鍵點僅與文本完美對應。我想讓他們將文字複製到新圖像上。

我該如何繪製keypoints所指的對象?

source image

這裏的關鍵點 keypoints only

的輸出最終我想關鍵點只圖像有文本,而不是關鍵點標記

+0

爲此,您可能還需要在上下文中標識對象。然後,如果「關鍵點」位於檢測到的對象內,則可以突出顯示該特定對象。 –

+0

如何識別上下文中的對象? –

+0

您可以上傳您正在使用的示例圖片嗎 –

回答

0

不要看看這種方法。它不是很整潔,但你可以改進它來滿足你的需求。

我獲得使用cv2.ORB_create()給定的圖像,爲此,我得到這個關鍵點:

img = cv2.imread(filename,0) 
orb = cv2.ORB_create() 
kp = orb.detect(img,None) 
kp, des = orb.compute(img, kp) 

img2 = cv2.drawKeypoints(img,kp,None,color=(0,255,0), flags=0) 
cv2.imshow('keypoint_on_text.jpg', img2) 

enter image description here

可以使用surf更好的檢測關鍵點。

然後,我獲得了具有與圖像相同形狀的純色(在這種情況下爲黑色)的圖像。我在這張黑色的圖像上畫出了這些獲得的關鍵點。

mask = np.zeros((img.shape[0], img.shape[1], 3), np.uint8) 
mask[:] = (0, 0, 0) 

fmask = cv2.drawKeypoints(mask,kp,None,color=(0,255,0), flags=0) 
cv2.imshow('fmask.jpg', fmask) 

enter image description here

現在我轉換這對灰度圖像和應用的閾值進行二值化它。然後我在這幅圖像上找到了輪廓,並以更大的半徑繪製輪廓。

graymask = cv2.cvtColor(fmask,cv2.COLOR_BGR2GRAY) 
ret, th = cv2.threshold(graymask, 50, 255, 0) 
_, contours , _= cv2.findContours(th,2,1) 
rep = cv2.drawContours(fmask, contours, -1, (0,255,0), 5) 
cv2.imshow('contours.jpg',rep) 

enter image description here

我轉換這灰度,二值化,並與原始圖像掩蓋它,最終得到這樣的:

repmask = cv2.cvtColor(rep,cv2.COLOR_BGR2GRAY) 
ret, th1 = cv2.threshold(repmask, 50, 255, 0) 
res = cv2.bitwise_and(img,img,mask = th1) 
cv2.imshow('Only_Text.jpg',res) 

enter image description here

正如你所看到的,某些所需文本的部分是可見的。如果您使用surf檢測,您將能夠獲取更多部分的文本。

+0

如果您需要編碼方面的幫助,請確保伸手。我希望這有幫助。那裏可能會有更好的方法。但這首先讓我感到震驚。 :D –

+0

你能提供你如何做到:「我把它轉換成灰度,將它二值化並用原始圖像掩蓋它,最終獲得這個」? –

+0

再次檢查解決方案。我已經添加了相關的代碼。 –

相關問題