Python 确定大图中是否包含小图
小图:
大图:
完整代码:
# coding: utf-8
import os, sys
import cv2
import time
import win32api
import win32con
import aircv as ac
from PIL import ImageGrab
from log_module import LogClassimport numpy as npparent_path = os.path.dirname(os.path.abspath(__file__))
sys.path.append(parent_path)class CheckHDMirror(LogClass):"""CheckHDMirror"""def __init__(self):"""__init__"""LogClass.__init__(self, logName='CheckHDMirror')self.setTimedRotatingFileHandler(fileName='CheckHDMirror')self.img_path = parent_path + "\\img\\" # 截图路径self.scale = 1self.result = False # 结果def search_point(self, img, template, template_size):img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)template_ = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)result = cv2.matchTemplate(img_gray, template_, cv2.TM_CCOEFF_NORMED)threshold = 0.9loc = np.where(result >= threshold) # 相似度大于90%point = ()for pt in zip(*loc[::-1]):cv2.rectangle(img, pt, (pt[0] + template_size[1], pt[1] + + template_size[0]), (7, 249, 151), 2)point = ptif point == ():return None, None, Nonereturn img, point[0] + template_size[1] / 2, point[1]def get_position(self):try:# im = ImageGrab.grab()# if os.path.exists(self.img_path) is False:# os.makedirs(self.img_path)# im.save(self.img_path + "screenshot.png") # 全屏截图保存mirrir_img = self.img_path + "mirrir.png"hd_img = self.img_path + "hd.png"max_img = self.img_path + "screenshot.png"# 方法一:# max_img = cv2.imread(max_img) # 要找的大图# max_img = cv2.resize(max_img, (0, 0), fx=self.scale, fy=self.scale)## hd_img = cv2.imread(hd_img) # 图中的小图# hd_img = cv2.resize(hd_img, (0, 0), fx=self.scale, fy=self.scale)# hd_img_size = hd_img.shape[:2]## mirrir_img = cv2.imread(mirrir_img) # 图中的小图# mirrir_img = cv2.resize(mirrir_img, (0, 0), fx=self.scale, fy=self.scale)# mirrir_img_size = mirrir_img.shape[:2]## hd, x_, y_ = self.search_point(max_img, hd_img, hd_img_size)# mirrir, x_, y_ = self.search_point(max_img, mirrir_img, mirrir_img_size)# 方法二:max_img_pos = ac.imread(max_img)hd_img_pos = ac.imread(hd_img)m_img_pos = ac.imread(mirrir_img)hd = ac.find_template(max_img_pos, hd_img_pos) # 在大图中找小图mirrir = ac.find_template(max_img_pos, m_img_pos)if hd and mirrir:if float(hd["confidence"]) > 0.9 and float(mirrir["confidence"]) > 0.9: # 相似度大于90%position = hd["result"] # 坐标print(position)self.result = Trueelse:self.result = Falseelse:self.result = Falseself.logger.info("Is it the same?: %s" % self.result)return self.resultexcept Exception as e:self.logger.error(e)def run(self):self.logger.info("begin")self.get_position()self.logger.info("end")if __name__ == '__main__':z = CheckHDMirror()z.run()
Python 确定大图中是否包含小图相关推荐
- python 从大图中找小图
#python 从大图中找小图 今天突然想到这样的问题,找了一下,没找到解决方法,自己想试一试就做了一个,但是感觉太白痴,但是运行的时候也不是说要很久. #!/usr/bin/env python3 ...
- CSS从大图中抠取小图完整教程(background-position应用)
转:http://www.cnblogs.com/iyangyuan/archive/2013/06/01/3111704.html 相信很多喜欢研究网页界面的童鞋都遇到过一个奇妙的现象:网页中很多图 ...
- CSS从大图中抠取小图完整教程(background-position应用) (转)
自认为把background-position的应用讲得非常通俗易懂的教材.做个记号. 相信很多喜欢研究网页界面的童鞋都遇到过一个奇妙的现象:网页中很多图片素材被合成在一张图片上. 起初小菜模仿网站的 ...
- CSS从大图中抠取小图完整教程(background-position应用)【转】
相信很多喜欢研究网页界面的童鞋都遇到过一个奇妙的现象:网页中很多图片素材被合成在一张图片上. 起初小菜模仿网站的时候,经常遇到这个现象,那时候也不知道这时什么技术,人家的整张图片素材不会利用,只能用p ...
- python判断lt中是否包含数字0_python中用for判断alt;b-女性时尚流行美容健康娱乐mv-ida网...
自动秒收录 如何加入 (当前页) 购买本站源码 自媒体交流 查询是否收录 查询收录 × 快速加入 只要做上本站的友情链接,并在您站上点击一次,就免人工自动收录!并自动排在本站第一位. 本站已收录286 ...
- python 为什么元组中只包含一个元素时,需要在元素后面添加逗号?(消除歧义)
为什么要写成这样呢? tup1=(50,) 目的:消除歧义,如: a = (1) # <class 'int'> print(type(a))b = (1,) print(type(b)) ...
- mysql 反向匹配子串,Mysql 模糊匹配(字符串str中是否包含子字符串substr)
1.LIKE 通常与 % 一同使用,类似于一个元字符的搜索.若substr不在str中,则返回0. SELECT 'test' LIKE '%e%' as `ret`; # 1 SELECT 'tes ...
- python获取小图在大图中的坐标和相似度
python获取小图在大图中的坐标和相似度 模块安装:pip install aircv 大小两个图片:big.jpg,small.jpg 模块安装:pip install aircv 大小两个图片: ...
- Python中pandas检查dataframe中是否包含某个字段、或者数据列实战、检查dataframe中是否包含某个字段集合
Python中pandas检查dataframe中是否包含某个字段.或者数据列(column)实战 目录 Python中pandas检查dataframe中是否包含某个字段.或者数据列(column) ...
最新文章
- Depth graph
- 自定义组件 点击空白处隐藏
- 【剑指offer】_02替换空格
- sarscape 将dem文件转化成stl_SARscape与SARProz软件中的重要缩写
- Java hibernate假外键_java – Hibernate:外键的列数错误
- 微博粉丝平台开发全攻略
- 解决SQL server不支持utf8,php却用utf8的矛盾问题
- Truthman or Fakeman 并查集
- 有关VS2008制作安装包时遇到的问题详解
- python json操作_Python读取JSON数据操作实例解析
- 蓝湖怎么切图标注_蓝湖:你们要的“自动切图”功能来了!
- 池塘cPond分享会第5期 • 守望者联盟 • 巴比特副总裁马千里 • 数字艺术对Web3的价值...
- SSM思想—阶段性总结
- MPLS之LDP的工作原理和配置
- 苹果cms v8模板仿q2002电影网站电脑手机自适应模板
- Dynamics CRM REST Builder
- Docker基础-使用Dockerfile创建镜像
- os模块的使用方法详解
- vs2012 MFC连接及操作access(2007)数据库(ADO)
- Ubuntu 安装make