#!/usr/bin/python
# -*- coding: UTF-8 -*-
#Less than 10 add to list and sort
import glob
import os
import sys
from functools import reduce
from PIL import Image EXTS = 'jpg', 'jpeg', 'JPG', 'JPEG', 'gif', 'GIF', 'png' def avhash(im):
if not isinstance(im, Image.Image):
im = Image.open(im)
if im.mode=='RGBA':
im=ConvertRBGA(im)
im = im.resize((8, 8), Image.ANTIALIAS).convert('L')
avg = reduce(lambda x, y: x + y, im.getdata()) / 64.0
return reduce(lambda x, y_z: x | (y_z[1] << y_z[0]), enumerate(map(lambda i: 0 if i < avg else 1, im.getdata())), 0) def hamming(h1, h2):
h, d = 0, h1 ^ h2
while d:
h += 1
d &= d - 1
return h def ConvertRBGA(img):
x,y = img.size
# # (alpha band as paste mask).
p = Image.new('RGBA', img.size, (255,255,255))
p.paste(img, (0, 0, x, y),img)
return p if __name__ == '__main__':
#if len(sys.argv) <= 1 or len(sys.argv) > 3:
# print ("Usage: %s image.jpg [dir]" % sys.argv[0])
#else:
# im, wd = sys.argv[1], '.' if len(sys.argv) < 3 else sys.argv[2]
im, wd = 'gs6.png', '.' if len(sys.argv) < 3 else sys.argv[2]
h = avhash(im)
os.chdir(wd);
images = []
for ext in EXTS:
images.extend(glob.glob('*.%s' % ext)) seq = []
prog = int(len(images) > 50 and sys.stdout.isatty())
for f in images:
result=avhash(f)
seq.append((f, hamming(result, h)))
if prog:
perc = 100. * prog / len(images)
x = int(2 * perc / 5)
print ('\rCalculating... [' + '#' * x + ' ' * (40 - x) + ']'),
print ('%.2f%%' % perc, '(%d/%d)' % (prog, len(images))),
sys.stdout.flush()
prog += 1 if prog: print
for f, ham in sorted(seq, key=lambda i: i[1]):
print ("%d\t%s" % (ham, f))

感知哈希算法 python 3.4的更多相关文章

  1. 感知哈希算法——Python实现【转】

    转自:https://blog.csdn.net/m_buddy/article/details/78887248 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原 ...

  2. 感知哈希算法的java实现

    一.原理讲解      实现这种功能的关键技术叫做"感知哈希算法"(Perceptual Hash Algorithm), 意思是为图片生成一个指纹(字符串格式), 两张图片的指纹 ...

  3. 谷歌百度以图搜图 "感知哈希算法" C#简单实现

    /// <summary> /// 感知哈希算法 /// </summary> public class ImageComparer { /// <summary> ...

  4. Iconfinder 如何杜绝盗版,哈希算法检测图像重复

    原地址:http://blog.jobbole.com/65914/ 本文由 伯乐在线 - 小鱼 翻译自 Silviu Tantos.欢迎加入技术翻译小组.转载请参见文章末尾处的要求. [伯乐在线导读 ...

  5. 压缩感知重构算法之IRLS算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  6. 压缩感知重构算法之OLS算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  7. 压缩感知重构算法之CoSaMP算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  8. 压缩感知重构算法之IHT算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

  9. 压缩感知重构算法之SP算法python实现

    压缩感知重构算法之OMP算法python实现 压缩感知重构算法之CoSaMP算法python实现 压缩感知重构算法之SP算法python实现 压缩感知重构算法之IHT算法python实现 压缩感知重构 ...

随机推荐

  1. Win10下Mysql5.7.13,解压版安装流程

    一.环境变量配置 1.将下载好的压宿包解压到安装目录,我的安装目录就是:D:\DevelopmentTool\Mysql5.7.13\mysql-5.7.13-winx64 2.鼠标选择计算机右键,点 ...

  2. html css jquery 回到顶部按钮

    今天做了个回到顶部的功能,在这里记录一下,有需要可以拿去试试! CSS部分,很简单就一个class /*回到顶部*/ .back-top { position: fixed; right: 15px; ...

  3. 关于Python2字符编码的体会

    对于Python的字符编码问题也懵了很久,最近做爬虫多次遇到网页转码的问题,干脆彻底解决掉!Just Do it! 1.两种类型str与unicode str和unicode都是basestring的 ...

  4. jvm原理及调优

    一.java内存管理及垃圾回收 jvm内存组成结构 jvm栈由堆.栈.本地方法栈.方法区等部分组成,结构图如下所示: (1)堆 所有通过new创建的对象的内存都在堆中分配,堆的大小可以通过-Xmx和- ...

  5. IE9 浏览器无法捕获中键事件

    在silverlight中由于需要添加中键事件,所以通过hook来捕获,但是在IE9上无法运行,该问题是由于IE9设置问题,如下图修改配置, 取消选择即可:

  6. EF OrderBy(string propertyname), OrderByDescending(string propertyname) 按属性排序,扩展方法

    public static class LinqExtensions { private static PropertyInfo GetPropertyInfo(Type objType, strin ...

  7. 怎么给当前点击的a标签添加一个样式(跳转页面后)

    怎么给当前点击的a标签添加一个样式(跳转页面后): 方法1. 用cookie记录这个打开的序列号,然后页面在跳转的时候在读出来.方法2. 循环a的链接,然后与location.href去比对,如果相同 ...

  8. Location-aware Associated Data Placement for Geo-distributed Data-intensive Applications--INFOCOM 2015

    [标题] [作者] [来源] [对本文评价] [why] 存在的问题 [how] [不足] assumption future work [相关方法或论文] [重点提示] [其它]

  9. fidder https以及Fiddler抓取HTTPS协议

    一.浅谈HTTPS 我们都知道HTTP并非是安全传输,在HTTPS基础上使用SSL协议进行加密构成的HTTPS协议是相对安全的.目前越来越多的企业选择使用HTTPS协议与用户进行通信,如百度.谷歌等. ...

  10. each用法的总结

    1.选择器+遍历 $('div').each(function (i){ i就是索引值 this 表示获取遍历每一个dom对象 }); 2.选择器+遍历 $('div').each(function  ...