2012-04-23 126 views
0

我嘗試使用MatchTemplate()來匹配圖像中的數字。例如,圖片中的數字是[0985-977-735]。 (0,1),(3,103),(5,33),(5,116),(7,62),(7,73),(5),(7),(7),(7),(7) ,(7,85),(8,21),(9,11),(9,53)]如何提高OpenCV模板匹配的準確性

但是在大多數情況下,準確度非常低。 (0,113),(1,93),(3,31),(4,62),(5,74),(8,103),(3),(3),(4),(6), (9,11),(9,53)] 第一個零和八個不能被識別。 (0,103),(2,31),(3,21),(5,54),(6,92),(7,113),(7,113),(7,114), 9,72)] 第一個,第二個零和第九個不能被識別。 (1,102),(1,33),(2,113),(3,72),(5,105),(5,105) 7,92),(8,52),(9,11)] 前七位無法識別。代碼

部分如下:

import cv 
for i in range(10): 
    template_im = cv.LoadImage(template_file, cv.CV_LOAD_IMAGE_GRAYSCALE) 
    width = original_im.width - template_im.width + 1 
    height = original_im.height - template_im.height +1 
    result_image = cv.CreateImage((width, height), cv.IPL_DEPTH_32F, 1) 
    cv.Zero(result_image) 
    cv.MatchTemplate(original_im, template_im, result_image, cv.CV_TM_CCOEFF_NORMED) 
    (_, R, _, max_loc) = cv.MinMaxLoc(result_image) 

    if R < 0.90: 
     pass 
    else: 
     phone_number_location.append((i, max_loc[0])) 
     ... 
     ... 
+1

你可以發佈你正在處理的圖像樣本嗎? – sinelaw 2012-04-23 15:55:34

+0

如果你正在尋找一個數字OCR,你可以在這裏看到一個簡單的實現使用OpenCV-Python.http://stackoverflow.com/questions/9413216/simple-digit-recognition-ocr-in-opencv-python/9620295# 9620295 – 2012-04-23 17:17:01

+0

可能重複[在Android上使用OpenCV進行數字識別](http://stackoverflow.com/questions/10107258/digit-recogntion-using-opencv-on-android) – karlphillip 2012-04-23 17:50:27

回答

0

你可能喜歡使用SimpleCV這一點。它是用python編寫的。你需要的大部分東西都在裏面。我用15行代碼寫了一個基本的圖像拼接應用程序。希望這可以幫助。使用github中的代碼是因爲SimpleCV中新增了模板匹配。 希望這有助於。

+0

謝謝,我會試試看! – Jasoniem9246 2012-04-24 03:34:58