Python实现图片对比
以下内容转载自大牛该大牛,链接点击跳转
具体实现逻辑:使用第三方的控件,将两张图片进行对比,两张图片的尺寸必须一致。然后才能对比。
# USAGE
# python image_diff.py --first images/original_01.png --second images/modified_01.png# import the necessary packages
from skimage.measure import compare_ssim
import argparse
import imutils
import cv2# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--first", required=True,help="first input image")
ap.add_argument("-s", "--second", required=True,help="second")
args = vars(ap.parse_args())# load the two input images
imageA = cv2.imread(args["first"])
imageB = cv2.imread(args["second"])# convert the images to grayscale
grayA = cv2.cvtColor(imageA, cv2.COLOR_BGR2GRAY)
grayB = cv2.cvtColor(imageB, cv2.COLOR_BGR2GRAY)# compute the Structural Similarity Index (SSIM) between the two
# images, ensuring that the difference image is returned
(score, diff) = compare_ssim(grayA, grayB, full=True)
diff = (diff * 255).astype("uint8")
print("SSIM: {}".format(score))# threshold the difference image, followed by finding contours to
# obtain the regions of the two input images that differ
thresh = cv2.threshold(diff, 0, 255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)# loop over the contours
for c in cnts:# compute the bounding box of the contour and then draw the# bounding box on both input images to represent where the two# images differ(x, y, w, h) = cv2.boundingRect(c)cv2.rectangle(imageA, (x, y), (x + w, y + h), (0, 0, 255), 2)cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 0, 255), 2)# show the output images
cv2.imshow("Original", imageA)
cv2.imshow("Modified", imageB)
cv2.imshow("Diff", diff)
cv2.imshow("Thresh", thresh)
cv2.waitKey(0)
Python实现图片对比相关推荐
- python找图片不同_用openCV和Python 实现图片对比,并标识出不同点的方式
最近项目中需要实现两组图片对比,并能将两者的区别标识出来. 在网上搜索一大堆找到一篇大神的文章,最终实现该功能,在这里记录下: 想要实现此demo,首先我们得确保电脑上已安装 openCV 和 Pyt ...
- 用openCV 和 Python 实现图片对比,并标识出不同点
最近项目中需要实现两组图片对比,并能将两者的区别标识出来. 在网上搜索一大堆找到一篇大神的文章,最终实现该功能,在这里记录下: 想要实现此demo,首先我们得确保电脑上已安装 openCV 和 Pyt ...
- python简单图片对比
# -*- coding: utf-8 -*- import cv2,os import time import numpy as np from matplotlib import pyplot a ...
- python图片比对、自动化测试_基于python+appium通过图片对比来做的UI自动化
1.python + appium +图片对比实现UI自动化: 背景: 当手机需要适配不同的语言时,测试过程中易出现因为语言不熟悉,导致UIbug被遗漏(例如setting中的描述性文字显示不完整等等 ...
- python图像对比_python+PIL实现图片对比(一)
前提 前阵子报了个班,学了一些android UI自动化相关的东西,于是想到第一家单位在做android手机自动化的时候,有用到图片对比,来确定是否点到指定的页面,遂想在appium+python做U ...
- Python学习之图片对比和识别小记
因工作中需要对视频图片做处理,于是就把应用得到的几个需求功能在网上solo了一波. 一.图片对比 主要应用的库Image,函数Image.size(),resize(),convert(),getpi ...
- cv2 和 matplotlib.pyplot 和 PIL.Image 读取图片方式对比【Python读取图片】
文章目录 import matplotlib.pyplot as plt 和 cv2 读取图像对比 PIL 和 cv2 读取图片对比 mxnet.image.imread 读取图片 PIL 和 tor ...
- 安卓自动化之uiautomator(python篇)常用adb及图片对比
学完前面的几节知识后,发觉uiautomator里面的方法并不能完全满足我们的要求,因此我们需要其他的东西来帮助我们解决问题 1.图片对比(当有些控件不能识别的时候,比如设置两次壁纸是否一样,我们就可 ...
- python识别图片指定位置文字_python批量识别图片指定区域文字内容
Python批量识别图片指定区域文字内容,供大家参考,具体内容如下 简介 对于一张图片,需求识别指定区域的内容 1.截取原始图上的指定图片当做模板 2.根据模板相似度去再原始图片上识别准确坐标 3.根 ...
最新文章
- JAX_WS 2.2 规范的webservices客户端实现(Axis2,Cxf)
- 多线程学习(二)----AfxBeginThread
- JAVA设置新视口,java – 在更大的图像上移动视口; JLablel JScrollPane
- jaxb 生成java类_重用生成的JAXB类
- Android中常见功能包描述
- 使用Xmanger登陆aix系统桌面时报桌面服务DT未启动问题
- 开课吧Java课堂:如何使用isAlive()和join()
- 中国国家统计局2021年版行政区划完整版
- OOP思想与Java实现
- 《CSS权威指南》读书笔记4
- 基于单神经元的自适应PID算法实现步骤与MATLAB代码
- [备忘] 下载youtube表单的工具
- Error occurred when evaluating apply
- 【2017.11.16】外包单报价
- 谷歌又在开发新AI框架!这次瞄准的是:通用人工智能(AGI)
- [译] Cilium:基于 BPF+EDT+FQ+BBR 更好地带宽网络管理
- PreparedStatement的executeQuery、executeUpdate和execute
- Hadoop-HA集群启动后两个namenode都是standby问题。
- Git入门以及提升书籍推荐
- Java 通过BufferedImage缩放和裁剪图片
热门文章
- 微商难做?不存在的,手把手教你做微商
- Matlab中的循环
- 关于useGeneratedKeys的用法
- 王者荣耀妲己樱桃雪顶怎么获得
- python创建方法draw_Python生成便签图片的方法总结
- 自学《HTML5+CSS 32网站设计基础教程》 第一章
- 上半年净利润下滑163%,做电商SaaS的光云科技为何“面露难色”?
- 华为手机鸿蒙好不好,华为鸿蒙6月2日正式上线,其未来前景到底怎么样?
- 大学生HTML CSS动漫主题网页制作——刀剑神域(6页) dreamweaver作业静态HTML网页设计
- grep和sed配合替换文件中的字串