def main(): db = get_db_engine() items = db.execute("select id, shop_id, local_pic_url, concat('/space/wwwroot/image.guang.j.cn/ROOT/images/', shop_id, '/mid2/', local_pic_url) as img_path from item where status=1 and %s order by id" % FLAGS.where) for item in items: img_path = item[3] if not os.path.exists(img_path) or img_path.endswith('.png'): logger.warn('skipping %s %s', item[0], item[3]) continue try: logger.debug('processing %s %s', item[0], item[3]) d = ','.join(map(str, pHash.image_digest(img_path, 1.0, 1.0, 180).coeffs)) db.execute("insert ignore into item_image_digest (item_id, digest) values (%s, '%s')" % (item[0], d)) except: pass
def main(): db = get_db_engine() items = db.execute( "select id, shop_id, local_pic_url, concat('/space/wwwroot/image.guang.j.cn/ROOT/images/', shop_id, '/mid2/', local_pic_url) as img_path from item where status=1 and %s order by id" % FLAGS.where) for item in items: img_path = item[3] if not os.path.exists(img_path) or img_path.endswith('.png'): logger.warn('skipping %s %s', item[0], item[3]) continue try: logger.debug('processing %s %s', item[0], item[3]) d = ','.join( map(str, pHash.image_digest(img_path, 1.0, 1.0, 180).coeffs)) db.execute( "insert ignore into item_image_digest (item_id, digest) values (%s, '%s')" % (item[0], d)) except: pass
while (1): image_url = str(photo_url + str(photo_id) + "_102_73_1.jpg") try: e = browser.find_element_by_name('imageDescription[' + str(photo_id) + ']') except: print "We've reached all the images we could find" end_id = photo_id - 1 break urllib.urlretrieve(image_url, str(photo_id) + '.jpg') image1 = Image.open(str(photo_id) + '.jpg') images = find_images('thumbnails') photo_id += 1 photo_id = orig_photo_id for i in images: digest1 = pHash.image_digest(str(photo_id) + '.jpg', 1.0, 1.0, 180) digest2 = pHash.image_digest(str('thumbnails/' + i), 1.0, 1.0, 180) if pHash.crosscorr(digest1, digest2) == 1: if photo_id < end_id: photo_to_id[photo_id] = i photo_id += 1 print name_to_num for ident in photo_to_id: repl = re.sub('IMG_', '', str(photo_to_id[ident])) photo_num = re.sub('.jpg', '', repl) if name_to_num[photo_num]: try: e = browser.find_element_by_name("imageDescription[" + str(ident) + "]") e.send_keys(name_to_num[photo_num]) except:
#!/usr/bin/env python # coding: utf-8 import sys import pHash if __name__ == "__main__": if len(sys.argv) != 3: print "usage: ${prog} src dst" sys.exit(0) d1 = pHash.image_digest(sys.argv[1], 1.0, 1.0, 180) d2 = pHash.image_digest(sys.argv[2], 1.0, 1.0, 180) print 'digest', pHash.crosscorr(d1, d2)[1] h1 = pHash.imagehash(sys.argv[1]) h2 = pHash.imagehash(sys.argv[2]) print 'hash', pHash.hamming_distance(h1, h2)
#!/usr/bin/env python import sys import pHash if __name__ == "__main__": src = sys.argv[1] dst = sys.argv[2] d1 = pHash.image_digest(src, 1.0, 1.0, 180) d2 = pHash.image_digest(dst, 1.0, 1.0, 180) print pHash.crosscorr(d1, d2)[1]
photo_id = orig_photo_id while ( 1 ): image_url = str(photo_url + str(photo_id) + "_102_73_1.jpg") try: e = browser.find_element_by_name('imageDescription[' + str(photo_id) + ']') except: print "We've reached all the images we could find" end_id = photo_id - 1 break urllib.urlretrieve(image_url, str(photo_id) + '.jpg') image1 = Image.open(str(photo_id) + '.jpg') images = find_images('thumbnails') photo_id += 1 photo_id = orig_photo_id for i in images: digest1 = pHash.image_digest(str(photo_id) + '.jpg', 1.0, 1.0, 180) digest2 = pHash.image_digest(str('thumbnails/' + i), 1.0, 1.0, 180) if pHash.crosscorr(digest1, digest2) == 1: if photo_id < end_id: photo_to_id[photo_id] = i photo_id += 1 print name_to_num for ident in photo_to_id: repl = re.sub('IMG_', '', str(photo_to_id[ident])) photo_num = re.sub('.jpg', '', repl) if name_to_num[photo_num]: try: e = browser.find_element_by_name("imageDescription[" + str(ident) + "]") e.send_keys(name_to_num[photo_num]) except: print "Sorry couldn't find that element " + str(ident)