try {
//capture = new VideoCapture(openFileDialog.FileName);
float threshold = 0.1f;
var imgScene = new Image<Bgr, byte>(openFileDialog.FileName);
Mat imgOut = new Mat();
CvInvoke.MatchTemplate(imgScene, template, imgOut, Emgu.CV.CvEnum.TemplateMatchingType.Sqdiff);
Mat imgoutNorm = new();
CvInvoke.Normalize(imgOut, imgoutNorm,0,1, Emgu.CV.CvEnum.NormType.MinMax);
Matrix<double> matches = new Matrix<double>(imgoutNorm.Size);
imgoutNorm.CopyTo(matches);
double minValue = 0, maxVal = 0;
Point minLoc = new Point();
Point maxLoc = new Point();
do
{
CvInvoke.MinMaxLoc(matches, ref minValue, ref maxVal, ref minLoc, ref maxLoc);
Rectangle r = new Rectangle(minLoc, template.Size);
CvInvoke.Rectangle(imgScene, r, new MCvScalar(255, 0, 0), 1);
matches[minLoc.Y, minLoc.X] = 0.5;
matches[maxLoc.Y, maxLoc.X] = 0.5;
} while (minValue <= threshold);
pictureBox1.Image = imgScene.AsBitmap();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
CvInvoke.MinMaxLoc(matches, ref minValue, ref maxVal, ref minLoc, ref maxLoc);
должно было как то это регулировать походу раз ссылки + переменная макс меняется. private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
try {
//capture = new VideoCapture(openFileDialog.FileName);
var imgScene = new Image<Bgr, byte>(openFileDialog.FileName);
Mat imgOut = new Mat();
CvInvoke.MatchTemplate(imgScene, template, imgOut, Emgu.CV.CvEnum.TemplateMatchingType.CcoeffNormed);
Mat imgoutNorm = new();
CvInvoke.Normalize(imgOut, imgoutNorm,0,1, Emgu.CV.CvEnum.NormType.MinMax);
float[,] matches = (float[,])imgoutNorm.GetData();
for (int y = 0; y < matches.GetLength(0); y++)
{
for (int x = 0; x < matches.GetLength(1); x++)
{
double matchScore = matches[y, x];
if (matchScore > 0.99)
{
Rectangle rect = new Rectangle(new Point(x, y), template.Size);
imgScene.Draw(rect, new Bgr(Color.Blue), 1);
}
}
}
pictureBox1.Image = imgScene.AsBitmap();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
//capture.Read(img);
// pictureBox1.Image = img.ToBitmap();
}
}