前言
C#图片特征比对:
通过AI 算法,查找两张图片的相似点,特征点的比对比例分析,如果达到90% 以上,默认相同或者相似。
一、FREAK算法
FREAK算法是2012年CVPR上《FREAK: Fast Retina Keypoint》文章中,提出来的一种特征提取算法,也是一种二进制的特征描述算子。它与BRISK算法非常相似,个人觉得就是在BRISK算法上的改进,关于BRISK算法详见上一篇博文:BRISK特征提取算法。FREAK依然具有尺度不变性、旋转不变性、对噪声的鲁棒性等。
二、使用步骤
1.引入库
代码如下(示例):
using ImageAi;
using System;
using System.Drawing;
using System.Windows.Forms;
2.提交数据
代码如下(示例):
ImageAiClass imageAi = new ImageAiClass();
ImageAi.Event.OnResult += Event_OnResult;
imageAi.BitmapA = Bitmap 图片数据1;
imageAi.BitmapB = Bitmap 图片数据2;
imageAi.flag = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
imageAi.Open();
3.获取识别结果
代码如下(示例):
private void Event_OnResult(Result e)
{
if (e.error == "OK")
{
string tempString = string.Format("[{6}]原图采样点:{0},对比图采样点:{1},匹配个数点:{2},{3},匹配比例:{4}%,{5}%",
e.original, e.target, e.match[0], e.match[1], e.ratio[0], e.ratio[1],e.flag);
this.Invoke(new Action(() =>
{
lb_result.Text = tempString;
lb_result.BackColor = Color.Azure;
}));
}
else
{
this.Invoke(new Action(() =>
{
lb_result.Text = "["+e.flag+"]"+e.error;
lb_result.BackColor = Color.Azure;
}));
}
}
4.识别结果定义
代码如下(示例):
using System;
namespace ImageAi
{
public class Result
{
public Result()
{
this.error = "OK";
}
public string flag { get; set; } /**提交的标志**/
public int original { get; set; }/**原图采样点**/
public int target { get; set; }/**目标图采样点**/
public int[] match { get; set; }/**匹配采样点(原图,目标图)**/
public decimal[] ratio { get; set; }/**匹配率(原图对目标图,目标图对原图)**/
public string error { get; set; } /**结果:OK为成功,其他为失败原因**/
}
}
示例资源
下载示例资源:https://download.csdn.net/download/qq_42945182/85073691