Ejemplo n.º 1
0
def filename_listener(request):
    predict, name = None, None
    if request.method == 'POST':
        filename =  request.POST.get('filename')
        print filename
        imgFilesPathsWithLabels = {}
        imgFilesPathsWithLabels[filename] = 0 
        dictWordsImages=getWordsInImages(imgFilesPathsWithLabels, Dense=True, disableSIFTWrite=True)
        print "Using trained vocabulary or visual words"
        print "------------------------------------------------------"
        centroidFile = open('leaf/CENTROID.file')
        centroids=load(centroidFile)
        print "Computing Histogram from centroids"
        allwordVocabularyHistrogram=computeHistrogramByLevel(centroids,dictWordsImages)
        print "------------------------------------------------------"
        print "write the histogram.out"
        modelFile = open('leaf/model.file')
        clf = load(modelFile)
        predict, name =  clf.predict(allwordVocabularyHistrogram.values())[0], allwordVocabularyHistrogram.keys()[0]
	
    jsonData = json.dumps({'predict':predict})
    return HttpResponse(jsonData, content_type='application/json')
PRE_ALLOCATION_BUFFER = 1000

print "------------------------------------------------------"
print "Generation SIFT words"
print "------------------------------------------------------"

if len(sys.argv) > 5 and sys.argv[5] == "Dense":
    Dense = True
else:
    Dense = False

centroids = getCentroids()
f = open(sys.argv[2] + "/" + "histrogram.out", "w")

datasetDir = sys.argv[2] + "/" + "Images"
for file in os.listdir(datasetDir):
    name = datasetDir + "/" + file
    imgFilesPathsWithLabels = {}
    dictWordsImages = {}
    imgFilesPathsWithLabels[name] = ""
    dictWordsImages = getWordsInImages(imgFilesPathsWithLabels,
                                       disableSIFTWrite=True,
                                       Dense=Dense)
    allwordVocabularyHistrogram = computeHistrogramByLevel(
        centroids,
        dictWordsImages)  #computeHistrogram(centroids,dictWordsImages)
    imgId = name.split("/")[3]
    print imgId
    d = map(str, (allwordVocabularyHistrogram[name]).tolist())
    print >> f, imgId, " ".join(d)
Ejemplo n.º 3
0
		print "------------------------------------------------------"
		dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,Dense=True)
else:
	print "Generation SIFT words"
	print "------------------------------------------------------"
	try:
		if sys.argv[6] and sys.argv[7]:
			for dirList in labels:
				masksDir=sys.argv[7]+"/"+dirList
				for file in os.listdir(masksDir):
					masksPath[sys.argv[2]+"/"+dirList+"/"+file]=masksDir+"/"+file
		dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,masksPath,Dense=False)
	except IndexError:
		print "No masks avilable"
		print "------------------------------------------------------"
		dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,Dense=False)

print "Using trained vocabulary or visual words"
print "------------------------------------------------------"
centroids=getCentroids()
print "Coumputing Histrogram from centroids"
allwordVocabularyHistrogram=computeHistrogramByLevel(centroids,dictWordsImages)#computeHistrogram(centroids,dictWordsImages)
print "------------------------------------------------------"
print "write the histogram.out"
file=open(sys.argv[2]+"/"+"histrogram.out","w")
for name in allwordVocabularyHistrogram.keys():
	print name
	imgId=name.split("/")[2]
	d=map(str,(allwordVocabularyHistrogram[name]).tolist())
	print >>file,imgId," ".join(d)
print "------------------------------------------------------"