コード例 #1
0
def search_img_url(query, distance):
    if ' ' in query:
        query = query.replace(' ', '%20')

    if not is_valid_url(query):
        raise Exception("Invalid query: '%s'" % query)

    try:
        hash = db.get_image_hash_from_url(url=query)

        if not hash:
            # Download image
            web = Httpy()
            try:
                image_buffer = web.download(url=query)
            except:
                raise Exception('unable to download image at %s' % query)

            try:
                im = image_from_buffer(image_buffer)
                hash = get_hash(im)
            except:
                raise Exception("Could not identify image")

        images = db.get_similar_images(hash, distance=distance)
        results = build_results_for_images(images)

    except Exception as e:
        return Response(json.dumps({'error': str(e)}), mimetype="application/json")

    return Response(results.json(), mimetype="application/json")
コード例 #2
0
def search_vid_url(query, distance, frame_count):
    if ' ' in query:
        query = query.replace(' ', '%20')

    try:
        video_id = db.get_video_from_url(url=query)

        if not video_id:
            # Download video
            web = Httpy()
            video_buffer = web.download(url=query)
            if not video_buffer:
                raise Exception('unable to download video at %s' % query)

            try:
                frames, info = info_from_video_buffer(video_buffer, os.path.splitext(query)[1][1:])
            except:
                raise Exception("Could not identify video")

            videos = db.get_similar_videos_by_hash(frames, distance, frame_count)

        else:

            hashes = db.get_video_hashes(video_id)
            videos = db.get_similar_videos_by_hash(hashes, distance, frame_count)

        results = SearchResults(db.build_results_for_videos(videos))

    except Exception as e:
        return Response(json.dumps({'error': str(e)}), mimetype="application/json")

    return Response(results.json(), mimetype="application/json")
コード例 #3
0
ファイル: ImageHash.py プロジェクト: 4pr0n/irarchives
	im.thumbnail( (100, 100), Image.ANTIALIAS)
	im.save('thumbs%s%d.jpg' % (sep, num), 'JPEG')
	del im
	

if __name__ == '__main__':
	args = argv[1:]
	if len(args) == 0:
		print 'argument required: image file location'
		exit(1)
	filename = ' '.join(args)
	remove_file = False
	if not path.exists(filename):
		if '://' in filename:
			web = Httpy()
			web.download(filename, 'img.jpg')
			filename = 'img.jpg'
			remove_file = True
		else:
			print 'file not found: %s' % (filename)
			exit(1)
	
	print 'Hash:\t\t%d' % avhash(filename)
	
	print ''
	d = avhash_dict(filename)
	for key in d:
		print 'Hash[%s] = \t%d' % (key, d[key])
	print ''
	
	dim = dimensions(filename)
コード例 #4
0
    im.thumbnail((100, 100), Image.ANTIALIAS)
    im.save('thumbs%s%d.jpg' % (sep, num), 'JPEG')
    del im


if __name__ == '__main__':
    args = argv[1:]
    if len(args) == 0:
        print 'argument required: image file location'
        exit(1)
    filename = ' '.join(args)
    remove_file = False
    if not path.exists(filename):
        if '://' in filename:
            web = Httpy()
            web.download(filename, 'img.jpg')
            filename = 'img.jpg'
            remove_file = True
        else:
            print 'file not found: %s' % (filename)
            exit(1)

    print 'Hash:\t\t%d' % avhash(filename)

    print ''
    d = avhash_dict(filename)
    for key in d:
        print 'Hash[%s] = \t%d' % (key, d[key])
    print ''

    dim = dimensions(filename)