Professional Documents
Culture Documents
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
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;
namespace realtime_surf
{
public partial class Form1 : Form
{
//member variables
Capture capWebcam;
bool blnWebcamCapturingInProcess = false;
Image<Bgr, byte> imgSceneColor = null;
Image<Bgr, byte> imgToFindColor = null;
Image<Bgr, byte> imgCopyOfImageToFindWidthBorder = null;
bool blnImageSceneLoaded = false;
bool blnImageToFindLoaded = false;
Image<Bgr, byte> imgResult = null;
Bgr bgrKeyPointColor = new Bgr(Color.Blue);
Bgr bgrMatchingLinesColor = new Bgr(Color.Green);
Bgr bgrFoundImageColor = new Bgr(Color.Red);
Stopwatch stopwatch = new Stopwatch();
public Form1()
{
InitializeComponent();
}
imgSceneColor = null;
imgToFindColor = null;
imgCopyOfImageToFindWidthBorder = null;
imgResult = null;
blnImageSceneLoaded = false;
blnImageToFindLoaded = false;
txtImageScene.Text = "";
txtImageToFind.Text = "";
ibResult.Image = null;
this.Text = "Instruction : use \",,,\" buttons to choose both image
file, theb press Perform SURF Button";
btnPerformSURFOrGetImageToTrack.Text = "Perform SURF Detection";
ibResult.Image = null;
label1.Visible = true;
label2.Visible = true;
txtImageScene.Visible = true;
txtImageToFind.Visible = true;
btnImageScene.Visible = true;
btnImageToFind.Visible = true;
}
}
if ((rdoImageFile.Checked == true)) {
btnPerformSURFOrGetImageToTrack_Click(new object(), new
EventArgs());
}
}
int intKNumNearestNeighbors = 2;
double dblUniquenessThreshold = 0.8;
int intNumNonZeroElements = 0;
double dblScaleIncrement = 1.5;
int intRotationBins = 20;
double dblRansacReprojectionThreshold = 2.0;
Features2DToolbox.VoteForUniqueness(mtxDistance,
dblUniquenessThreshold, mtxMask);
intNumNonZeroElements = CvInvoke.cvCountNonZero(mtxMask);
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;
ptfPointsF = new PointF[] {
new PointF(rectImageToFind.Left, rectImageToFind.Top),
new PointF(rectImageToFind.Right, rectImageToFind.Top),
new PointF(rectImageToFind.Right, rectImageToFind.Bottom),
new PointF(rectImageToFind.Left, rectImageToFind.Bottom)};
homographyMatrix.ProjectPoints(ptfPointsF);
ptPoints = new Point[] {
Point.Round(new
PointF(rectImageToFind.Left,rectImageToFind.Top)),
Point.Round(new PointF(rectImageToFind.Right,
rectImageToFind.Top)),
Point.Round(new PointF(rectImageToFind.Right,
rectImageToFind.Bottom)),
Point.Round(new PointF(rectImageToFind.Left,
rectImageToFind.Bottom))};
ibResult.Image = imgResult;
if ((rdoImageFile.Checked == true)) {
stopwatch.Stop();
this.Text = "processing time = " +
stopwatch.Elapsed.TotalSeconds.ToString() + "Sec, done processing,
choose another image if desired";
}
}
}
}