def compute(i):
img_file = files[i]
img = cv2.imread(img_file, cv2.CV_LOAD_IMAGE_GRAYSCALE)
if img is None:
print 'img {} is None, path correct? --> skip'.format(img_file)
return
kpts = fe.detect(img)
_, descriptors = fe.extract(img, kpts)
if descriptors is None or len(descriptors) == 0:
print 'WARNING: no descriptors extracted, skip image', img_file
sys.exit(1)
# Hellinger normalization
descriptors += np.finfo(np.float32).eps
descriptors /= np.sum(descriptors, axis=1)[:,np.newaxis]
descriptors = np.sqrt(descriptors)
# output
new_basename = os.path.join(args.outputfolder,
os.path.basename(os.path.splitext(img_file)[0]))
feat_filename = new_basename + '_' + args.detector \
+ '_' + args.feature + '.pkl.gz'
with gzip.open(feat_filename, 'wb') as f:
cPickle.dump(descriptors, f, -1)
progress.update(i+1)
评论列表
文章目录