Exemplo n.º 1
0
def findSpaceLength(Histogram, High): 
    """function search expected length of space in line, based on empty columns in histogram, its a simple arithmetic mean of length of empty space"""
    summ=0
    length=0
    number=0
    for kol in Histogram:
        if kol==0:
            length+=1
        elif kol>0 and length>0:
            if length<High:
                summ+=length
                length=0
                number+=1
            else:length=0
    if number<>0:    return max(summ/number, (1/5)*High) ## in a case if there is no space in line
    else: return (1/5)*High
    
if __name__ == "__main__": #this runs, when code is running as an own program, not as a module
	#you can use this section to test your module

	f=open("line1.bmp","rb")
	Image=LineFrame(f)
	Image.blackWhite()
	kafels=Image.extractCharacters()
	for i in range(0,len(kafels)):
            for j in range(0, len(kafels[i])):
                kafels[i][j].savePicture(str(i)+"kafel"+str(j)+".bmp","BMP")
       # im=LineFrame(new=True)
        #im.showPicture()