当前位置:网站首页>AI 之 OpenCvSharp 大图找小图(案例版)
AI 之 OpenCvSharp 大图找小图(案例版)
2022-07-17 01:57:00 【dotNET跨平台】
要说跟AI扯上啥关系,估计只有库本身了,但是,这个大图搜小图功能还是不错的,有喜欢的可以试试。我主要用的场景是,具体的某个界面为大图,界面的某个图标为小图,或者,整个桌面为大图,某个小图标为小图这样来确定某个插件或者功能的位置。
之前也写了一下基于C#代码的找图,但是感觉效率不高,这次做个基于OpenCvSharp的找图功能,有喜欢的可以尝试下。
创建一个Winfrom项目
因为项目示例简单,但是,又需要获取桌面大小,得创建这样的项目。
要添加Nuget包
Install-Package OpenCvSharp4.Windows -Version 4.6.0.20220608查找主要业务代码
public static Rectangle Find(Image sourceImage, Image matchImage, double threshold = 0.8)
{
var refMat = Mat.FromImageData(ImageHelper.ImageToBytes(sourceImage), ImreadModes.AnyColor);//大图
var tplMat = Mat.FromImageData(ImageHelper.ImageToBytes(matchImage), ImreadModes.AnyColor);//小图
using (Mat res = new Mat(refMat.Rows - tplMat.Rows + 1, refMat.Cols - tplMat.Cols + 1, MatType.CV_32FC1))
{
Mat gref = refMat.CvtColor(ColorConversionCodes.BGR2GRAY);
Mat gtpl = tplMat.CvtColor(ColorConversionCodes.BGR2GRAY);
Cv2.MatchTemplate(gref, gtpl, res, TemplateMatchModes.CCoeffNormed);
Cv2.Threshold(res, res, 0.8, 1.0, ThresholdTypes.Tozero);
double minval, maxval;
Point minloc, maxloc;
Cv2.MinMaxLoc(res, out minval, out maxval, out minloc, out maxloc);
if (maxval >= threshold)
{
return new Rectangle(maxloc.X, maxloc.Y, tplMat.Width, tplMat.Height);
}
return Rectangle.Empty;
}
}可以根据相似度来实现搜索,其实如果直接屏幕截图的话,相似度都是0.99,还挺不错的。
多图结果返回的话,想研究的大佬,可以研究研究。
效果

可以看到查找速度还是很快的,当然,第一次可能会稍微慢点,近200毫秒了
总结
这个案例搞定,就意味着往WEB 页面滑动图解锁验证 自动化又前进了一步,后面想想如何做这个案例。
代码地址
https://github.com/kesshei/SearchImageDemo.git
https://gitee.com/kesshei/SearchImageDemo.git
阅
一键三连呦!,感谢大佬的支持,您的支持就是我的动力!
边栏推荐
- [2016 CCPC Hangzhou j] just a math problem (Mobius inversion)
- Boston house price analysis assignment summary
- Theoretical basis of double Q-learning and its code implementation [pendulum-v0]
- Reptile learning (5): teach you reptile requests practice hand in hand
- Game theory of catching lice
- Backup kubernetes backup etcd data
- STM32串口发送和接收多个数据教程基于气体传感器实战
- Monte Carlo based reinforcement learning method [with code implementation]
- Vs code problem: launch:program '... \ vscode\launch. exe‘ dose not exist
- 洛谷每日三题之第三天(第四天补做)
猜你喜欢

Chengxin University envi_ IDL second week homework: extract aerosol thickness at n points + detailed analysis

Bias and variance

Vscode+ros2 environment configuration

Zabbix6.0 monitoring vcenter7.0

Derivation of PCA principal component analysis (dimension reduction) process

Thinkphp5.0模型操作使用page进行分页
![Monte Carlo based reinforcement learning method [with code implementation]](/img/39/346b2f4122238eb0d51ca164ab6d86.png)
Monte Carlo based reinforcement learning method [with code implementation]

基于Pandoc与VSCode的 LaTeX环境配置

Browser cannot open tensorboard

Machine learning library scikit learn (linear model, ridge regression, insert a column of data, extract the required column, vector machine (SVM), clustering)
随机推荐
web语义化(强调标签-em-斜体)(重点强调标签-strong-粗体)(自定义列表:dl、dt、dd)
MySQL master-slave setup
Analysis and processing of male and female voice signals based on MATLAB
代理模式——B站动力节点
module_ Basic principle of init function
本地存储localStorage⽤法详解
Es6 notes d'étude - station B Xiao Ma Ge
The third day of the three questions of Luogu daily (make up on the fourth day)
Chapter I Introduction
Theoretical basis of double Q-learning and its code implementation [pendulum-v0]
KubeCon + CloudNativeCon Europe 2022
論文閱讀:U-Net++: Redesigning Skip Connections to Exploit Multiscale Features in Image Segmentation
Rhce8 Learning Guide Chapter 1 installing rhel8.4
神经网络学习笔记2.2 ——用Matlab写一个简单的卷积神将网络图像分类器
SwiftUI 考试题库项目之支持题库和考试题库数量(教程含源码)
鼠标滑动两张图片前后对比js插件
Dive into deep learning - 2.2 data preprocessing
模块(block、module)的介绍
leetcode:50. Pow(x, n)
Through openharmony compatibility evaluation, the big brother development board and rich teaching and training resources have been ready