Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@seaslee
Created March 30, 2013 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seaslee/5274998 to your computer and use it in GitHub Desktop.
Save seaslee/5274998 to your computer and use it in GitHub Desktop.
select images for codebook generation
# -*- coding: utf8 -*-
import csv
import os
def listimgs(metafilepath, imgfilepath, n):
#metafilepath: the path of the meta info of result
#n: the number of a query to generate the codebook
N = 355
imgs = []
for i in range(N):
temp = []
fn = os.path.join(metafilepath, 'meta_query_' + str(i) + '.dat')
if os.path.exists(fn):
with open(fn, 'rb') as csvf:
info = csv.reader(csvf, delimiter=' ')
for row in info:
temp.append([int(e) if j == 0 or j == 2 else e for (j, e) in enumerate(row)])
sinfo = sorted(temp, key=lambda x: x[2])
imgs.extend([os.path.join(imgfilepath, 'query_' + str(i), e[1].replace('textmeta.xml', 'imagethumb.jpg')) for e in sinfo[:n + 1]])
with open('cblist.txt', 'w') as f:
f.writelines('%s\n' % e for e in imgs)
print len(imgs)
return imgs
if __name__ == '__main__':
listimgs('WebQueries\\metasByQuery', 'WebQueries\\imagesByQuery', 20)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment