def extract_query(infile_list): featureID = 0 imageID = 0 NUMBER_OF_TABLES = 20 totalDescriptors = 0 f = open('./pig/query.csv', 'w') for file_name in infile_list: img = cv2.imread(file_name, 0) kp = orb.detect(img, None) kp, des = orb.compute(img, kp) numDescriptors = des.shape[0] totalDescriptors = totalDescriptors + numDescriptors contig = numpy.ascontiguousarray(des, dtype=numpy.uint8) hashes = lsh.hash(contig) # for each descriptor, get the 20 hash values cnt = 0 for descriptor in xrange(0, numDescriptors): f.write("%u, %u, " % (featureID, imageID)) for hash in xrange(0, NUMBER_OF_TABLES): f.write("%u, " % (hashes[cnt])) cnt = cnt + 1 f.write("\n") featureID = featureID + 1 imageID = imageID + 1 print "Wrote %u descriptor records\n" % (totalDescriptors) f.close()
kp = orb.detect(img, None) # compute the descriptors for the keypoints and store in a matrix kp, des = orb.compute(img, kp) # get the number of descriptors returned (number of rows) numDescriptors = des.shape[0] # keep track of the total number of descriptors processed totalDescriptors = totalDescriptors + numDescriptors # LSH requires access to a contiguous array for matrix processing contig = numpy.ascontiguousarray(des, dtype=numpy.uint8) # generate the hash values for all features in the descriptor matrix hashes = lsh.hash(contig) cnt = 0 # for each descriptor for descriptor in xrange(0, numDescriptors): # write out the FeatureID and ImageID f.write("%u, %u, " % (featureID, imageID)) # for each hash table for hash in xrange(0, NUMBER_OF_TABLES): # write out hash value for this image in this hash tab;e f.write("%u, " % (hashes[cnt])) cnt = cnt + 1 f.write("\n") featureID = featureID + 1 imageID = imageID + 1