Beispiel #1
0
def task_gen_top_tag_via_number(query, K, root):
    from photo_dao import PhotoDao
    from database import DBHelper
    db_helper = DBHelper()
    db_helper.init(root)

    photo_dao = PhotoDao(db_helper)
    photo_ids = photo_dao.getClassPhotoIds(query, ''.join([query]))

    photos = photo_dao.getPhotos(query, photo_ids)

    hist = {}
    for photo in photos:
        tags = photo.tags
        for tag in tags:
            if(tag in hist):
                hist[tag] = hist[tag] + 1
            else:
                hist[tag] = 0
    top_word_freq = sorted(hist.items(), key=lambda t: -t[1])
    top_word_freq = top_word_freq[0:min(len(top_word_freq), K)]
    top_word = []
    for line in top_word_freq:
        top_word.append(line[0].strip())

    output_path = ''.join([root, '/data/tags/%s.txt'%query])
    from file_io import FileIO
    file_io = FileIO()
    file_io.write_strings_to_file(top_word, output_path)

    return top_word
def get_photo_imagepath(root, query, image_ids):
    db = DBHelper()
    db.init(root)

    imagepaths =[]
    for image_id in image_ids:
        imagepath = db.getPhotoImgPath(query, image_id)
        imagepaths.append(imagepath)
    return imagepaths
Beispiel #3
0
def taskBuildAllFeatures():
    from photo_dao import PhotoDao
    from database import DBHelper
    db_helper = DBHelper()
    
    query = 'beauty'
    db_helper.init('D:/Iconic')
    photoDao = PhotoDao(db_helper)
    photoIds = photoDao.getClassPhotoIds(query, ''.join([query]))
    featureDao = FeatureDao()
    features = featureDao.read_features(query, photoIds, 'tag3000')
    featureDao.save_features(query, photoIds, 'tag3000', features)
def task_gen_photo_imagepath(root, query):
    print('Get photo ids.');
    db_helper = DBHelper();
    db_helper.init(root);

    photo_dao = PhotoDao(db_helper);

    tic();
    photo_ids = photo_dao.getClassPhotoIds(query, ''.join([query]));
    toc();

    print('Get photo path.');
    imagepaths = get_photo_imagepath(root, query, photo_ids)

    output_path = ''.join([db_helper.datasetDir, '/', query, '_imagepath.txt']);
    file_io = FileIO();
    file_io.write_strings_to_file(imagepaths, output_path);
Beispiel #5
0
def task_gen_photo_meta(root, query, do_save_meta):
	print('generating photo meta for %s'%(query));
	filter = PhotoFilter();
	dbHelper = DBHelper();
	dbHelper.init(root);
	photos = filter.get_photo_with_tag_and_unique(query, dbHelper);
	if (do_save_meta):
		photo_dao = PhotoDao(dbHelper)
		for photo in photos:
			photo_dao.savePhotoMeta(query, photo);
	photos = filter.filter_photo_without_tags(photos);

	outputPath = ''.join([dbHelper.datasetDir, '/', query, '.txt']);
	print(outputPath);
	fout = open(outputPath, 'w');
	for photo in photos:
		fout.write(photo.photoId)
		fout.write('\n')
	fout.close();
Beispiel #6
0
def task_gen_index_by_tag(query, root, top_tag_num, top_tags, photo_ids, output_root):
    from photo_dao import PhotoDao
    from database import DBHelper
    db_helper = DBHelper()
    db_helper.init(root)

    photo_dao = PhotoDao(db_helper)
    photos = photo_dao.getPhotos(query, photo_ids)
    top_tags_index = {}
    for i, tag in enumerate(top_tags):
        top_tags_index[tag] = i
    
    tag_image_index = ['']*top_tag_num
    for photo in photos:
        tags = photo.tags
        for tag in tags:
            if(tag in top_tags):
                tag_index = top_tags_index[tag]
                tag_image_index[tag_index] = ''.join([tag_image_index[tag_index], ',', photo.photoId])
    
    web_dao = WebPageResultDao()
    web_dao.init(output_root)
    for key in top_tags:
        tag_index = top_tags_index[key]
        line = tag_image_index[tag_index]
        line = line.strip()

        if (line != ""):
            tag_image_ids = []
            image_ids = line.split(',')
            for image_id in image_ids:
                image_id = image_id.strip()
                if (image_id != ""):
                    tag_image_ids.append(image_id)
            try:
                web_dao.save_photo_ids('tag_images/%s' % key, '1', tag_image_ids)
            except:
                print('error in generating %s' % key)
Beispiel #7
0
		photo_files = self.get_photo_meta_files(query, db_helper)
		photos = []
		photoBuilder = PhotoBuilder();
		for filepath in photo_files:
			items = photoBuilder.get_photo_from_file(filepath)
			photos.extend(items)
		return photos
		
		
	def get_photo_with_tag_and_unique(self, query, db_helper):
		metaFilePath = db_helper.getRawMetaFileDir(query);
		photos = self.get_photo_with_tag(metaFilePath);

#		photos = self.get_photo_metas(query, db_helper)

		photos = self.filter_photo_tags(photos);
		print(len(photos));
		photos = self.make_unique_user(photos);
		print(len(photos));
		return photos;

if __name__ == "__main__":
	root = '../../../../test_dir'
	db_helper = DBHelper()
	db_helper.init(root)
	filter = PhotoFilter()
	photos = filter.get_photo_meta_files('art', db_helper)
	print (photos[0:10])
	print (len(photos))