|
源码如下:
//设置区域
System.Drawing.Rectangle rect1 = new Rectangle(x,y,w,h);
CvInvoke.cvSetImageROI(src, rect1 );
//模板
System.Drawing.Size size1 = new System.Drawing.Size(10,h-2);
Image<Gray, Byte> temp1 = new Image<Gray, Byte>(size1);
CvInvoke.cvSetZero(temp1);
//平滑处理
CvInvoke.cvSmooth(src, src, SMOOTH_TYPE.CV_GAUSSIAN, 5, 5,0,0);
int iwidth = src.Width - temp1.Width + 1;
int iheight = src.Height - temp1.Height + 1;
//匹配结果
Image<Gray, Byte> ftmp = new Image<Gray, Byte>(iwidth, iheight);
Double min_val = 0,min_val1 = 0;
Double max_val = 0,max_val1 = 0;
Point min_loc = new Point(0,0);
Point min_loc1;
Point max_loc = new Point(0,0);
Point max_loc1;
//int i = 0;
//匹配
CvInvoke.cvMatchTemplate(src, temp1, ftmp, TM_TYPE.CV_TM_SQDIFF);
在C#环境下运行,出现问题,执行到匹配时,直接退出。输出错误:Emgu.CV.Util.CvException”类型的第一次机会异常在 Emgu.CV.dll 中发生。该代码在C++环境运行正常。
请指点,在线等。
CvInvoke.cvMinMaxLoc(ftmp, ref min_val, ref max_val, ref min_loc, ref max_loc, new IntPtr(0));
|
|