Python_Python图片对比
来源:互联网 发布:彩虹6号围攻低配优化 编辑:程序博客网 时间:2024/04/29 02:42
def make_regalur_image(img, size = (256, 256)):
return img.resize(size).convert('RGB')
def split_image(img, part_size = (64, 64)):
w, h = img.size
pw, ph = part_size
assert w % pw == h % ph == 0
return [img.crop((i, j, i+pw, j+ph)).copy() \
for i in xrange(0, w, pw) \
for j in xrange(0, h, ph)]
def hist_similar(lh, rh):
assert len(lh) == len(rh)
return sum(1 - (0 if l == r else float(abs(l - r))/max(l, r)) for l, r in zip(lh, rh))/len(lh)
def calc_similar(li, ri):
# return hist_similar(li.histogram(), ri.histogram())
return sum(hist_similar(l.histogram(), r.histogram()) for l, r in zip(split_image(li), split_image(ri))) / 16.0
def calc_similar_by_path(lf, rf):
li, ri = make_regalur_image(Image.open(lf)), make_regalur_image(Image.open(rf))
return calc_similar(li, ri)
def make_doc_data(lf, rf):
li, ri = make_regalur_image(Image.open(lf)), make_regalur_image(Image.open(rf))
li.save(lf + '_regalur.png')
ri.save(rf + '_regalur.png')
fd = open('stat.csv', 'w')
fd.write('\n'.join(l + ',' + r for l, r in zip(map(str, li.histogram()), map(str, ri.histogram()))))
# print >>fd, '\n'
# fd.write(','.join(map(str, ri.histogram())))
fd.close()
import ImageDraw
li = li.convert('RGB')
draw = ImageDraw.Draw(li)
for i in xrange(0, 256, 64):
draw.line((0, i, 256, i), fill = '#ff0000')
draw.line((i, 0, i, 256), fill = '#ff0000')
li.save(lf + '_lines.png')
if __name__ == '__main__':
path = r'D:\\Android\\android-sdk\\tools\\hui800\\getImage\\TEST%d\\%d.png'
for i in xrange(1, 7):
print 'test_case_%d: %.3f%%'%(i,\
calc_similar_by_path('D:\\Android\\android-sdk\\tools\\hui800\\getImage\\TEST%d\\%d.png'%(i, 1), \
'D:\\Android\\android-sdk\\tools\\hui800\\getImage\\TEST%d\\%d.png'%(i, 2))*100)
关于图片比对大家可以参考以下文章:
http://blog.csdn.net/lanphaday/article/details/2325027
#!/usr/bin/python
# -*- coding: utf-8 -*-
import Image
def make_regalur_image(img, size = (256, 256)):
return img.resize(size).convert('RGB')
def split_image(img, part_size = (64, 64)):
w, h = img.size
pw, ph = part_size
assert w % pw == h % ph == 0
return [img.crop((i, j, i+pw, j+ph)).copy() \
for i in xrange(0, w, pw) \
for j in xrange(0, h, ph)]
def hist_similar(lh, rh):
assert len(lh) == len(rh)
return sum(1 - (0 if l == r else float(abs(l - r))/max(l, r)) for l, r in zip(lh, rh))/len(lh)
def calc_similar(li, ri):
# return hist_similar(li.histogram(), ri.histogram())
return sum(hist_similar(l.histogram(), r.histogram()) for l, r in zip(split_image(li), split_image(ri))) / 16.0
def calc_similar_by_path(lf, rf):
li, ri = make_regalur_image(Image.open(lf)), make_regalur_image(Image.open(rf))
return calc_similar(li, ri)
def make_doc_data(lf, rf):
li, ri = make_regalur_image(Image.open(lf)), make_regalur_image(Image.open(rf))
li.save(lf + '_regalur.png')
ri.save(rf + '_regalur.png')
fd = open('stat.csv', 'w')
fd.write('\n'.join(l + ',' + r for l, r in zip(map(str, li.histogram()), map(str, ri.histogram()))))
# print >>fd, '\n'
# fd.write(','.join(map(str, ri.histogram())))
fd.close()
import ImageDraw
li = li.convert('RGB')
draw = ImageDraw.Draw(li)
for i in xrange(0, 256, 64):
draw.line((0, i, 256, i), fill = '#ff0000')
draw.line((i, 0, i, 256), fill = '#ff0000')
li.save(lf + '_lines.png')
if __name__ == '__main__':
path = r'test/TEST%d/%d.JPG'
for i in xrange(1, 7):
print 'test_case_%d: %.3f%%'%(i, \
calc_similar_by_path('test/TEST%d/%d.JPG'%(i, 1), 'test/TEST%d/%d.JPG'%(i, 2))*100)
# make_doc_data('test/TEST4/1.JPG', 'test/TEST4/2.JPG')
- Python_Python图片对比
- Python_python图片识别小程序
- Python_Python安装包下载
- Python_python plugin chilkat
- Python_Python 连接SSH
- Python_Python plugin 列表
- Python_python 创建目录
- Python_Python中的easy_install
- Python_Python环境变量PYTHONPATH设置
- Python_Python网络编程
- Python_python读写plist文件
- python_python学习_nametuple
- python_python学习_Json
- MonkeyRunner_MonkeryRunner图片对比代码
- Monkeyrunner图片对比
- Android图片对比源码
- android图片对比
- Pillow实现图片对比
- C# 引用类型作为函数参数时一些需要注意的地方
- 一个shell脚本调用另外一个脚本
- 模块计算机类型“IA64”与目标计算机类型“x64”冲突---解决方案
- 酷6正努力成为第一家实现盈利的视频网站
- 学习PHP面向对象(四)_get(),_set()的用法 这种方法不推荐使用
- Python_Python图片对比
- 建造者模式
- hadoop作业执行之TaskTracker
- 集群服务器管理相关开源工具
- js闭包和闭包范围
- chrome使用的开源工程
- Oracle 常用SQL技巧收藏
- 20120803重载覆盖和隐藏(overload,override and hide)
- 程序员面试题精选(14)-圆圈中最后剩下的数字