簡體   English   中英

清潔OCR圖像上的黑點

[英]Clean black point on the image for OCR

我想用python清除圖像上的黑點。 因為我需要對圖像文件應用ocr處理。

我將圖像轉換為單眼色,這樣我得到了這個圖像; http://s23.postimg.org/bulq1dmt3/ba210.png

所以,我想刪除黑點;

def temizleHips2 (x,y,w,h,listei):
koordinat=list(nfind(x,y))
x = int(x)
y = int(y)
w = int(w)
h = int(h)
i=0
a=0
m=4
b=0
for i in xrange(8):
        b=0
        k=koordinat[i]
        x2,y2=koordinatparse(k)
        if x2>=0 and y2>=0 and x2<w and y2<h:
            if listei[x2,y2]==0:
                a=a+1
if a>2:
    return 0
else:
    return 255

def ultratemizle(dosya):    
# 290a.tif
image_file = dosya
img = Image.open(image_file)
# img=img.convert('1')
# img.save("209i.tif","TIFF")
datas = list(img.getdata())
newData = list()
temizlemes = list()
temizlemeson = list()
siyah =0
beyaz =0
for each in datas:
    if each == 255:
        beyaz = beyaz +1
    else:
        siyah = siyah+1
if siyah > beyaz :
    for each in datas:
        if each == 255:
            each=0
        elif each==0:
            each = 255
        newData.append(each)
    img.putdata(newData)
x1,y1=0,0

tmp_isim = "a"+dosya
img.save("b"+tmp_isim, "TIFF")
img = Image.open(tmp_isim)
imgmat = img.load()
x,y= img.size
x1=0
y1=0
deger =0
temizlemes =[]
for x1 in range (0,x):
    for y1 in  range(0,y):
        if imgmat[x1,y1] == 0:
            deger = temizleHips(x1,y1,x,y,imgmat)
            temizlemes.append(deger)
            if deger != imgmat[x1,y1]:
                print "noktalar : "+str(x1)+","+str(y1)+" ilk : "+str(imgmat[x1,y1])+" son: "+str(deger)
        else:
            temizlemes.append(imgmat[x1,y1])
img.putdata(temizlemes)
img.show()
img.save(tmp_isim,"TIFF")

tem = img.load()

我得到這個形象; http://s16.postimg.org/wc97bdzdt/a356.png但是,我想在第二張圖片上的黑色像素周圍清除“ s”。 我找不到問題所在

您應該嘗試找到較大的輪廓並刪除其他輪廓

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM