陈程的技术博客

  • 关于作者
全栈软件工程师
一个专注于技术研究创新的程序员
  1. 首页
  2. python
  3. 正文

python版本的图片比较相似度

2021年8月25日 728点热度 0人点赞 0条评论

之前写过有C#版本的功能,此为python版本参考:

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
from PIL import ImageGrab
import os
import sys

imtest = ImageGrab.grab((0,0,1000,1000)) #可以添加一个坐标元组进去
imtest.save('test.png')

img_rgb = cv.imread('test.png')
img_gray = cv.cvtColor(img_rgb, cv.COLOR_BGR2GRAY)
template = cv.imread('5.png', 0)
h, w = template.shape[:2]

res = cv.matchTemplate(img_gray, template, cv.TM_CCOEFF_NORMED)
threshold = 0.9
# 取匹配程度大于90%的坐标
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):  # *号表示可选参数
    bottom_right = (pt[0] + w, pt[1] + h)
    cv.rectangle(img_rgb, pt, bottom_right, (0, 0, 255), 2)

if os.path.exists('test.png'):
    os.remove('test.png')
cv.imshow('img_rgb', img_rgb)
cv.waitKey(0)
cv.destroyAllWindows()

 

标签: python
最后更新:2021年8月25日

博主

全栈工程师,侧重项目技术解决方案规划和开发

打赏 点赞
< 上一篇
下一篇 >

文章评论

取消回复

分类
  • .NET (65)
  • docker (3)
  • linux (12)
  • python (20)
  • web (14)
  • 小程序 (4)
  • 数据库 (2)
  • 未分类 (4)
  • 杂七杂八 (10)
标签聚合
centos C# linux python js nginx winform DevExpress
最新 热点 随机
最新 热点 随机
.NET开发手册标准参考 招募兼职前端开发 Centos安装dotnet6环境 VS上切换分支,vs编译运行出现bug,A fatal error was encountered彻底解决方案 用C#封装一个线程安全的缓存器,达到目标定时定量更新入库 C#通过特性的方式去校验指定数据是否为空
RAP2 接口Mock工具部署使用 winform 绘制无边框拉伸功能,被覆盖边界也可拉伸 python 批量剪切图片指定区域 nginx配置命令 错误处理 ssh登陆提示:server unexpectedly closed network connection JsonHelper序列化和反序列化

COPYRIGHT © 2021 陈程的技术博客. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS