Created
March 30, 2013 02:18
-
-
Save seaslee/5274998 to your computer and use it in GitHub Desktop.
select images for codebook generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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