def correlationTop(target, directory): best = -1 bestFile = "" for libImage in os.listdir(directory): if libImage[0] != ".": thisCorrelation = oneDPearsonHelp(target, algo2.centerCut(Image.open(directory + libImage))) if thisCorrelation > best: best = thisCorrelation bestFile = libImage return (bestFile, best)
def distanceTop(target, directory): best = sys.maxint bestFile = "" for libImage in os.listdir(directory): if libImage[0] != ".": thisDist = rawDistanceHelp(target, algo2.centerCut(Image.open(directory + libImage))) if thisDist < best: best = thisDist bestFile = libImage return (bestFile, best)
def correlationTop(target, directory): best = -1 bestFile = "" for libImage in os.listdir(directory): if libImage[0] != ".": thisCorrelation = oneDPearsonHelp( target, algo2.centerCut(Image.open(directory + libImage))) if thisCorrelation > best: best = thisCorrelation bestFile = libImage return (bestFile, best)
def distanceTop(target, directory): best = sys.maxint bestFile = "" for libImage in os.listdir(directory): if libImage[0] != ".": thisDist = rawDistanceHelp( target, algo2.centerCut(Image.open(directory + libImage))) if thisDist < best: best = thisDist bestFile = libImage return (bestFile, best)
def classify(target, directory=dropBoxDir): target = Image.open(target) try: target_crop = algo2.centerCut(target) except: return (None, False, None, None) topFileByDist, topDistVal = distanceTop(target_crop, directory) if topDistVal < 20: #Strong Classification return ('library/' + topFileByDist, True, topDistVal, None) elif topDistVal < 40: #Weak Classification return ('library/' + topFileByDist, False, topDistVal, None) else: topFileByCorr, topCorrVal = correlationTop(target_crop, directory) parent = 'library/' + topFileByDist if parent != topFileByCorr: parent = None return (parent, False, topDistVal, topCorrVal)
def classify(target, directory = dropBoxDir): target = Image.open(target) try: target_crop = algo2.centerCut(target) except: return (None, False, None, None) topFileByDist, topDistVal = distanceTop(target_crop, directory) if topDistVal < 20: #Strong Classification return ('library/' + topFileByDist, True, topDistVal, None) elif topDistVal < 40: #Weak Classification return ('library/' + topFileByDist, False, topDistVal, None) else: topFileByCorr, topCorrVal = correlationTop(target_crop, directory) parent = 'library/' + topFileByDist if parent != topFileByCorr: parent = None return (parent, False, topDistVal, topCorrVal)