技术标签: C# OpenCv 图像处理 EMGU.CV WPF
模板匹配函数
参数说明
参数1:输入图像
参数2:匹配模板
参数3:返回矩阵
参数4:算法类型
其中算法类型共计六种:
//
// 摘要:
// This function is similiar to cvCalcBackProjectPatch. It slids through image,
// compares overlapped patches of size wxh with templ using the specified method
// and stores the comparison results to result
//
// 参数:
// image:
// Image where the search is running. It should be 8-bit or 32-bit floating-point
//
// templ:
// Searched template; must be not greater than the source image and the same data
// type as the image
//
// result:
// A map of comparison results; single-channel 32-bit floating-point. If image is
// WxH and templ is wxh then result must be W-w+1xH-h+1.
//
// method:
// Specifies the way the template must be compared with image regions
//
// mask:
// Mask of searched template. It must have the same datatype and size with templ.
// It is not set by default.
public static void MatchTemplate(IInputArray image, IInputArray templ, IOutputArray result, TemplateMatchingType method, IInputArray mask = null)
参数1:输入MatchTemplate函数返回的矩阵
参数2、3、4、5:分别为最小值、最大值、最小值的位置、最大值的位置
//
// 摘要:
// Finds minimum and maximum element values and their positions. The extremums are
// searched over the whole array, selected ROI (in case of IplImage) or, if mask
// is not IntPtr.Zero, in the specified array region. If the array has more than
// one channel, it must be IplImage with COI set. In case if multi-dimensional arrays
// min_loc->x and max_loc->x will contain raw (linear) positions of the extremums
//
// 参数:
// arr:
// The source array, single-channel or multi-channel with COI set
//
// minVal:
// Pointer to returned minimum value
//
// maxVal:
// Pointer to returned maximum value
//
// minLoc:
// Pointer to returned minimum location
//
// maxLoc:
// Pointer to returned maximum location
//
// mask:
// The optional mask that is used to select a subarray. Use IntPtr.Zero if not needed
public static void MinMaxLoc(IInputArray arr, ref double minVal, ref double maxVal, ref Point minLoc, ref Point maxLoc, IInputArray mask = null)
绘制矩形
//
// 摘要:
// Draws a rectangle specified by a CvRect structure
//
// 参数:
// img:
// Image
//
// rect:
// The rectangle to be drawn
//
// color:
// Line color
//
// thickness:
// Thickness of lines that make up the rectangle. Negative values make the function
// to draw a filled rectangle.
//
// lineType:
// Type of the line
//
// shift:
// Number of fractional bits in the point coordinates
public static void Rectangle(IInputOutputArray img, Rectangle rect, MCvScalar color, int thickness = 1, LineType lineType = LineType.EightConnected, int shift = 0
// 1. 加载原图
var image1 = new Image<Bgr, byte>("bird1.png");
var image0 = image1.Mat.Clone();
var imgGray = new Mat();
CvInvoke.CvtColor(image0,imgGray,ColorConversion.Bgr2Gray);
PreviewImage1 = new WriteableBitmap(Bitmap2BitmapImage(Text(image1.Bitmap, "原图")));
// 2. 原图转灰度
PreviewImage2 = new WriteableBitmap(Bitmap2BitmapImage(Text(imgGray.Bitmap, "灰度")));
// 3. 加载模板
var img3 = new Mat("birdTemplate.png",0);
PreviewImage3 = new WriteableBitmap(Bitmap2BitmapImage(Text(img3.Bitmap, "模板")));
// 需要用到的一些参数
var res = new Mat();
double minLoc = 0, maxLoc = 0;
Point minPoint = new Point();
Point maxPoint = new Point();
// 4. Sqdiff取最小值
CvInvoke.MatchTemplate(imgGray, img3, res, TemplateMatchingType.Sqdiff);
CvInvoke.MinMaxLoc(res,ref minLoc,ref maxLoc, ref minPoint,ref maxPoint);
var img4 = image0.Clone();
CvInvoke.Rectangle(img4, new Rectangle(minPoint, img3.Size), new MCvScalar(0, 0, 255), 2);
PreviewImage4 = new WriteableBitmap(Bitmap2BitmapImage(Text(img4.Bitmap, "Sqdiff")));
// 5 .SqdiffNormed
CvInvoke.MatchTemplate(imgGray, img3, res, TemplateMatchingType.SqdiffNormed);
CvInvoke.MinMaxLoc(res, ref minLoc, ref maxLoc, ref minPoint, ref maxPoint);
var img5 = image0.Clone();
CvInvoke.Rectangle(img5, new Rectangle(minPoint, img3.Size), new MCvScalar(0, 0, 255), 2);
PreviewImage7 = new WriteableBitmap(Bitmap2BitmapImage(Text(img5.Bitmap, "SqdiffNormed")));
// 6 .Ccoeff
CvInvoke.MatchTemplate(imgGray, img3, res, TemplateMatchingType.Ccoeff);
CvInvoke.MinMaxLoc(res, ref minLoc, ref maxLoc, ref minPoint, ref maxPoint);
var img6 = image0.Clone();
CvInvoke.Rectangle(img6, new Rectangle(maxPoint, img3.Size), new MCvScalar(0, 0, 255), 2);
PreviewImage5 = new WriteableBitmap(Bitmap2BitmapImage(Text(img6.Bitmap, "Ccoeff")));
// 7 .CcoeffNormed
CvInvoke.MatchTemplate(imgGray, img3, res, TemplateMatchingType.CcoeffNormed);
CvInvoke.MinMaxLoc(res, ref minLoc, ref maxLoc, ref minPoint, ref maxPoint);
var img7 = image0.Clone();
CvInvoke.Rectangle(img7, new Rectangle(maxPoint, img3.Size), new MCvScalar(0, 0, 255), 2);
PreviewImage8 = new WriteableBitmap(Bitmap2BitmapImage(Text(img7.Bitmap, "CcoeffNormed")));
// 8 .Ccorr
CvInvoke.MatchTemplate(imgGray, img3, res, TemplateMatchingType.Ccorr);
CvInvoke.MinMaxLoc(res, ref minLoc, ref maxLoc, ref minPoint, ref maxPoint);
var img8 = image0.Clone();
CvInvoke.Rectangle(img8, new Rectangle(maxPoint, img3.Size), new MCvScalar(0, 0, 255), 2);
PreviewImage6 = new WriteableBitmap(Bitmap2BitmapImage(Text(img8.Bitmap, "Ccorr")));
// 9 .CcorrNormed
CvInvoke.MatchTemplate(imgGray, img3, res, TemplateMatchingType.CcorrNormed);
CvInvoke.MinMaxLoc(res, ref minLoc, ref maxLoc, ref minPoint, ref maxPoint);
var img9 = image0.Clone();
CvInvoke.Rectangle(img9, new Rectangle(maxPoint, img3.Size), new MCvScalar(0, 0, 255), 2);
PreviewImage9 = new WriteableBitmap(Bitmap2BitmapImage(Text(img9.Bitmap, "CcorrNormed")));
// 1. 加载原图
var image1 = new Image<Bgr, byte>("Test.png");
var image0 = image1.Mat.Clone();
var imgGray = new Mat();
CvInvoke.CvtColor(image0,imgGray,ColorConversion.Bgr2Gray);
PreviewImage1 = new WriteableBitmap(Bitmap2BitmapImage(Text(image1.Bitmap, "原图")));
// 2. 加载模板
var img3 = new Mat("testTemplate.png",0);
PreviewImage2 = new WriteableBitmap(Bitmap2BitmapImage(Text3(img3.Bitmap, "模板")));
// 3. 匹配
var res = new Mat();
CvInvoke.MatchTemplate(imgGray, img3, res, TemplateMatchingType.CcoeffNormed);
var img4 = image0.Clone();
var m = new Matrix<float>(res.Rows, res.Cols);
res.CopyTo(m);
var image = res.ToImage<Gray, byte>();
for (int i = 0; i < res.Rows; i++)
{
for (int j = 0; j < res.Cols; j++)
{
if (m[i, j] > 0.8)
{
CvInvoke.Rectangle(img4, new Rectangle(new Point(j, i), img3.Size), new MCvScalar(0, 0, 255), 2);
}
}
}
PreviewImage3 = new WriteableBitmap(Bitmap2BitmapImage(Text(img4.Bitmap, "结果")));
java有一题执行结果不对,但是我不知道错在哪里了,求高手认真解释,谢谢!执行结果始终为0.题目:定义一个名为Cuboid的长方体类,使其继承Rectangle类,其中包含一个表示高度的double型成员变量heig2016-12-09java有一题执行结果不对,但是我不知道错在哪里了,求高手认真解释,谢谢!执行结果始终为0.题目:定义一个名为Cuboid的长方体类,使其继承Rectangle类,...
数论开始唯一分解定理这里以一个例子作为讲解http://lightoj.com/volume_showproblem.php?problem=1341题目给两个数 a b,要求我们求[1,a]的因数对数,并且这对因数在[b,a]之间。思路:求出a的全部因子/2=从[1,a]的全部因子对数,求出[1,b)中a的因因子个数,有一个在外面那么肯定有一个在[b,a]内,所以用全部的因子对数减去[...
(function($){InitDOM = function(){ var option = arguments[0]; var baseHtml= ""; var default_pic = '&lt;img src="'+option.items[0].levelD+'" jqimg="'+option.items[0].levelD+'" height="'+op...
点击上方“芋道源码”,选择“设为星标”做积极的人,而不是积极废人!源码精品专栏精尽 Dubbo 原理与源码69 篇精尽 Netty 原理与源码61 篇中文详细注释的开源项目Java...
vue2+elTree 实现右键菜单
清单 7. pthread_cond_timedwait() 函数定义int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime);参数 abstime 在这里用来表示和超时时间相关的一
网上能找到使用说明,但总会有一些坑,感觉很难受1. 安装mysql的msi文件2. 安装navicat3. 登录本地mysql 服务,新建数据库testmingo4.导入数据备份文件库里面大概有这些表5.新建用户 gps 、admin用户密码为[email protected]*3df)34c$3116.安装模拟终端,一路next安装好以后,如下图修改配置文件BasicConfig启动以后如上图,如果登录按钮是置灰的说明数据库没有连接上,仔细检查数据库和808服务器地址也可以在设置中配置输入a
Elasticsearch时区问题
Android TV 相关的库,包括界面开发,播放器等等的收集,我并无法保证全部加入,必定会遗漏一些优秀的 TV 相关的库。
svn导出日志及修改文件D:cd D:\svn server\binsvn log -v https://ZJ-XX-XXXXXX/svn/blsrc/ > D:\bat\blsvn.loggit导出日志及修改文件git config --global log.date iso-strict-localgit log --pretty=" %an | %cd | %s %b" --date=format:'%Y-%m-%d %H:%M:%S' --name-status .
写样式,控制该合计行在最上方,不写默认在最下方/*这里是:table的合计*/.el-table{ display: flex; flex-direction: column;}/* order默认值为0,只需将表体order置为1即可移到最后,这样合计行就上移到表体上方 */.el-table__body-wrapper { order: 1;}/* 如果你的"价格1或者日期加了fixed,那你需要加上这俩行代码,但是加了以后,这俩行可能会影响到其他页面,所以合计页面
------- android培训、java培训、iOS培训、.Net培训期待与您交流! ----------IO流用来处理设备之间的数据传输,java对数据的传输是通过流的方式,java用于操作流的对象都在IO包中流按操作数据分为两种:字节流与字符流流按流向分为:输入流、输出流IO流常用基类字节流的抽象基类:InputStream、outputStream