Académique Documents
Professionnel Documents
Culture Documents
txtImageScene btnImageScene
txtImageToFind btnImageToFind
ckDrawMatchingLines
btnPerformSURFOrGetImageToTrack
ckDrawKeyPoint
s
ibResult
Source Code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.Features2D;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.CV.Util;
using System.Diagnostics;
namespace SURF_EMGUCV
{
public partial class Form1 : Form
{
try
{
imgSceneColor = new Image<Bgr, Byte>(txtImageScene.Text);
//'Image(Of Bgr, Byte) My_Image = New Image(Of Bgr, Byte)(txtImageScene.Text)
//'imgSceneColor = imgSceneColor.ToBitmap();
}
catch (Exception ex)
{
this.Text = ex.Message;
return;
}
blnImageSceneLoaded = true;
if (blnImageToFindLoaded == false)
ibResult.Image = imgSceneColor;
else
ibResult.Image = imgSceneColor.ConcateHorizontal(imgCopyOfImageToFindWidthBorder);
}
try
{
imgToFindColor = new Image<Bgr, Byte>(txtImageToFind.Text);
//'Image(Of Bgr, Byte) My_Image = New Image(Of Bgr, Byte)(txtImageScene.Text)
//'imgSceneColor = imgSceneColor.ToBitmap();
}
catch (Exception ex)
{
this.Text = ex.Message;
return;
}
blnImageToFindLoaded = true;
imgCopyOfImageToFindWidthBorder = imgToFindColor.Copy();
imgCopyOfImageToFindWidthBorder.Draw(new Rectangle(1, 1, imgCopyOfImageToFindWidthBorder.Width
- 3, imgCopyOfImageToFindWidthBorder.Height - 3), bgrFoundImageColor, 2);
if (blnImageSceneLoaded == true)
ibResult.Image = imgSceneColor.ConcateHorizontal(imgCopyOfImageToFindWidthBorder);
else
ibResult.Image = imgCopyOfImageToFindWidthBorder;
//if we get here, we both color imagesare good, we can begin SURF detection stuff . . .
SURFDetector surfDetector = new SURFDetector(500, false);
Image<Gray, byte> imgSceneGray = null;
Image<Gray, byte> imgToFindGray = null;
int intKNumNearestNeighbors = 2;
double dblUniquenessThreshold = 0.8;
int intNumNonZeroElements = 0;
intNumNonZeroElements = CvInvoke.cvCountNonZero(mtxMask);
if ((intNumNonZeroElements >= 4))
{
intNumNonZeroElements = Features2DToolbox.VoteForSizeAndOrientation(vkpToFindKeyPoints,
vkpSceneKeyPoints, mtxMatchIndices, mtxMask, dblScaleIncrement, intRotationBins);
if ((intNumNonZeroElements >= 4))
{
homographyMatrix =
Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(vkpToFindKeyPoints, vkpSceneKeyPoints,
mtxMatchIndices, mtxMask, dblRansacReprojectionThreshold);
}
}
imgCopyOfImageToFindWidthBorder = imgToFindColor.Copy();
imgCopyOfImageToFindWidthBorder.Draw(new Rectangle(1, 1, imgCopyOfImageToFindWidthBorder.Width
- 3, imgCopyOfImageToFindWidthBorder.Height - 3), bgrFoundImageColor, 2);
if ((homographyMatrix != null))
{
rectImageToFind.X = 0;
rectImageToFind.Y = 0;
rectImageToFind.Width = imgToFindGray.Width;
rectImageToFind.Height = imgToFindGray.Height;
homographyMatrix.ProjectPoints(ptfPointsF);
ibResult.Image = imgResult;
stopwatch.Stop();
this.Text = "processing time = " + stopwatch.Elapsed.TotalSeconds.ToString() + "Sec, done
processing, choose another image if desired";
}
private void ckDrawMatchingLines_CheckedChanged(object sender, EventArgs e)
{
btnPerformSURFOrGetImageToTrack_Click(new object(), new EventArgs());
}
}
}