├── templates ├── file.html~ ├── file.html ├── aviary.html~ ├── index.html └── aviary.html ├── hash.py ├── diff.js ├── hash_movie.py └── app.py /templates/file.html~: -------------------------------------------------------------------------------- 1 | filepicker.setKey(apiKey); 2 | -------------------------------------------------------------------------------- /templates/file.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 |hi
7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /hash.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import sys 3 | import imagehash 4 | hash = imagehash.average_hash(Image.open(sys.argv[1])) 5 | print 'ahash: ' + str(hash) 6 | 7 | hash = imagehash.phash(Image.open(sys.argv[1])) 8 | print 'phash: ' + str(hash) 9 | 10 | hash = imagehash.dhash(Image.open(sys.argv[1])) 11 | print 'dhash: ' + str(hash) 12 | -------------------------------------------------------------------------------- /diff.js: -------------------------------------------------------------------------------- 1 | function hashDiff(a, b) { 2 | var diff = 0; 3 | for (var i = 0; i < a.length && i < b.length; i++) { 4 | x = atoi(a[i]); 5 | y = atoi(b[i]); 6 | diff += Math.min( 7 | Math.abs(Math.min(x,y) + 16 - Math.max(x,y)), 8 | Math.abs(x - y)); 9 | } 10 | return diff; 11 | } 12 | 13 | function atoi(c) { 14 | return parseInt('0x' + c); 15 | } 16 | 17 | console.log(hashDiff(process.argv[2], process.argv[3])); 18 | -------------------------------------------------------------------------------- /hash_movie.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | from os import listdir 3 | import sys 4 | import pymongo 5 | import imagehash 6 | 7 | client = pymongo.MongoClient('localhost', 27017) 8 | db = client.hackny 9 | title = sys.argv[1] 10 | path = sys.argv[2] 11 | 12 | 13 | for img in listdir(path): 14 | ahash = imagehash.average_hash(Image.open(path + '/' + img)) 15 | phash = imagehash.phash(Image.open(path + '/' + img)) 16 | dhash = imagehash.dhash(Image.open(path + '/' + img)) 17 | imghash = { 18 | "title": title, 19 | "ahash": str(ahash), 20 | "phash": str(phash), 21 | "dhash": str(dhash), 22 | "filename": img 23 | } 24 | 25 | # print imghash 26 | db.images.insert(imghash) 27 | 28 | 29 | def usage(): 30 | print "usage: hash_movie
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
13 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/templates/aviary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
11 |
12 |
64 |
65 |
66 |
67 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/app.py:
--------------------------------------------------------------------------------
1 | from flask import Flask, render_template, request, jsonify
2 | import os
3 | import requests
4 | import urllib2
5 | import pymongo
6 | from PIL import Image
7 | import sys
8 | import imagehash
9 | import heapq
10 | import subprocess
11 | from bs4 import BeautifulSoup
12 | import json
13 |
14 | client = pymongo.MongoClient('localhost', 27017)
15 | db = client.hackny
16 | movieTitle = ''
17 | app = Flask(__name__, static_url_path = "", static_folder = "")
18 |
19 |
20 | def computeHash(filename):
21 | return str(imagehash.average_hash(Image.open(filename)))
22 |
23 | def query(target):
24 | mins = [[1000000, None], [1000000, None], [1000000, None], [1000000, None], [1000000, None]]
25 |
26 | for obj in db.images.find():
27 | # compute the hamming weight of the bitwise xor
28 | try:
29 | weight = bin(int(target, 16) ^ int(obj['ahash'], 16)).count('1')
30 | m = max(mins, key=lambda x:x[0])
31 |
32 | if weight > m[0]:
33 | m[0] = weight
34 | m[1] = obj
35 | print target, obj['ahash'], obj['filename']
36 | except:
37 | pass
38 |
39 | return mins
40 |
41 |
42 | def foursquare(query):
43 | url = 'https://api.foursquare.com/v2/venues/search?client_id=SIUVLZ0OHAY5YW1W4F0GCDD4XUP0ILCPU3UYXVQBY0SDWSIZ&client_secret=5AKY4AQ0I4F3OOBSB0IWOSFZNJDAPYMU0BEPF0MGIWJPINQ1&v=20130815&ll=40.7,-74&query=%s' % query
44 |
45 | data = urllib2.urlopen(url)
46 | soup = BeautifulSoup(data)
47 | dictionary = json.loads(str(soup))
48 | places = dictionary['response']['venues']
49 | lines = []
50 | for place in places:
51 | name = place['name']
52 | location = place['location']
53 | try:
54 | city = location['city']
55 | except:
56 | city = "NYC"
57 | try:
58 | state = location['state']
59 | except:
60 | city = "NY"
61 |
62 | line = '