HOME/Articles/

pil example find the number (snippet)

Article Outline

Python pil example 'find the number'

Functions in program:

  • def whatNumberIsThis(imgFilePath):

python find the number

Python pil example: find the number

def whatNumberIsThis(imgFilePath):
    matchedAr = []
    loadExmp = open('exFile.txt','r').read()
    loadExmp = loadExmp.split('\n')

    exImage = Image.open(imgFilePath)
    eIAr = np.array(exImage)
    eIAr = threshold(eIAr)
    eiArL = eIAr.tolist()

    imgToFind = str(eiArL)

    for eachExmp in loadExmp:
        if len(eachExmp) > 3 :
            eachExmp = eachExmp.split('::')
            numExmp = eachExmp[0]
            numAr = eachExmp[1]

            eachPix = numAr.split('],')
            eachPix_imgToFind = imgToFind.split('],')

            x=0;
            while(x < len(eachPix)):
                if eachPix[x] == eachPix_imgToFind[x]:
                    matchedAr.append(int(numExmp))
                x += 1        
    c=Counter(matchedAr)
    print(c)