I tried very hard. But I cannot find one point of interest in the SURF algorithm in Emgu CV. I wrote code for SURF. and I have problems that sometimes arise if the operator is next to my number "number 1", and sometimes it is not based on different images. Why is this so? based on the fact that homography is calculated as non-empty. how can i draw a circle or lines. who also have a problem. a circle or rectangle is drawn on a 0.0 point image. Please help me. I will be grateful.
public Image<Bgr, Byte> Draw(Image<Gray, byte> conditionalImage, Image<Gray, byte> observedImage, out long matchTime)
{
Stopwatch watch;
HomographyMatrix homography = null;
SURFDetector surfCPU = new SURFDetector(500, false);
VectorOfKeyPoint modelKeyPoints;
VectorOfKeyPoint observedKeyPoints;
Matrix<int> indices;
Matrix<byte> mask;
int k = 2;
double uniquenessThreshold = 0.8;
modelKeyPoints = surfCPU.DetectKeyPointsRaw(conditionalImage, null);
Matrix<float> modelDescriptors = surfCPU.ComputeDescriptorsRaw(conditionalImage, null, modelKeyPoints);
watch = Stopwatch.StartNew();
observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedImage, null);
Matrix<float> observedDescriptors = surfCPU.ComputeDescriptorsRaw(observedImage, null, observedKeyPoints);
BruteForceMatcher<float> matcher = new BruteForceMatcher<float>(DistanceType.L2);
matcher.Add(modelDescriptors);
indices = new Matrix<int>(observedDescriptors.Rows, k);
using (Matrix<float> dist = new Matrix<float>(observedDescriptors.Rows, k))
{
matcher.KnnMatch(observedDescriptors, indices, dist, k, null);
mask = new Matrix<byte>(dist.Rows, 1);
mask.SetValue(255);
Features2DToolbox.VoteForUniqueness(dist, uniquenessThreshold, mask);
}
int nonZeroCount = CvInvoke.cvCountNonZero(mask);
if (nonZeroCount >= 4)
{
nonZeroCount = Features2DToolbox.VoteForSizeAndOrientation(modelKeyPoints, observedKeyPoints, indices, mask, 1.5, 20);
if (nonZeroCount >= 4)
homography = Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(modelKeyPoints, observedKeyPoints, indices, mask, 2);
}
watch.Stop();
Image<Bgr, Byte> result = Features2DToolbox.DrawMatches(conditionalImage, modelKeyPoints, observedImage, observedKeyPoints,
indices, new Bgr(Color.Blue), new Bgr(Color.Red), mask, Features2DToolbox.KeypointDrawType.DEFAULT);
#region draw the projected region on the image
if (homography != null)
{
Rectangle rect = conditionalImage.ROI;
PointF[] pts = new PointF[] {
new PointF(rect.Left, rect.Bottom),
new PointF(rect.Right, rect.Bottom),
new PointF(rect.Right, rect.Top),
new PointF(rect.Left, rect.Top)};
homography.ProjectPoints(pts);
PointF _circleCenter = new PointF();
_circleCenter.X = (pts[3].X + ((pts[2].X - pts[3].X) / 2));
_circleCenter.Y = (pts[3].Y + ((pts[0].Y - pts[3].Y) / 2));
result.Draw(new CircleF(_circleCenter, 15), new Bgr(Color.Red), 10);
result.DrawPolyline(Array.ConvertAll<PointF, Point>(pts, Point.Round), true, new Bgr(Color.Cyan), 5);
}
#endregion
matchTime = watch.ElapsedMilliseconds;
return result;
}