public void Panorama_Example1()
{
Accord.Math.Random.Generator.Seed = 0;
// Let's start with two pictures that have been
// taken from slightly different points of view:
//
Bitmap img1 = Accord.Imaging.Image.Clone(Resources.dc_left);
Bitmap img2 = Accord.Imaging.Image.Clone(Resources.dc_right);
// Those pictures are shown below:
// ImageBox.Show(img1, PictureBoxSizeMode.Zoom, 640, 480);
// ImageBox.Show(img2, PictureBoxSizeMode.Zoom, 640, 480);
// Step 1: Detect feature points using Surf Corners Detector
var surf = new SpeededUpRobustFeaturesDetector();
var points1 = surf.ProcessImage(img1);
var points2 = surf.ProcessImage(img2);
// Step 2: Match feature points using a k-NN
var matcher = new KNearestNeighborMatching(5);
var matches = matcher.Match(points1, points2);
// Step 3: Create the matrix using a robust estimator
var ransac = new RansacHomographyEstimator(0.001, 0.99);
MatrixH homographyMatrix = ransac.Estimate(matches);
Assert.AreEqual(1.15707409, homographyMatrix.Elements[0], 1e-5);
Assert.AreEqual(-0.0233834628, homographyMatrix.Elements[1], 1e-5);
Assert.AreEqual(-261.8217, homographyMatrix.Elements[2], 1e-2);
Assert.AreEqual(0.08801343, homographyMatrix.Elements[3], 1e-5);
Assert.AreEqual(1.12451434, homographyMatrix.Elements[4], 1e-5);
Assert.AreEqual(-171.191208, homographyMatrix.Elements[5], 1e-2);
Assert.AreEqual(0.000127789128, homographyMatrix.Elements[6], 1e-5);
Assert.AreEqual(0.00006173445, homographyMatrix.Elements[7], 1e-5);
Assert.AreEqual(8, homographyMatrix.Elements.Length);
// Step 4: Project and blend using the homography
Blend blend = new Blend(homographyMatrix, img1);
// Compute the blending algorithm
Bitmap result = blend.Apply(img2);
// Show on screen
// ImageBox.Show(result, PictureBoxSizeMode.Zoom, 640, 480);
result = Accord.Imaging.Image.Clone(result);
#if NET35
// result.Save(@"C:\Projects\Accord.NET\framework\Unit Tests\Accord.Tests.Imaging\Resources\blend_net35.png", ImageFormat.Png);
Bitmap image = Accord.Imaging.Image.Clone(Properties.Resources.blend_net35);
#else
// result.Save(@"C:\Projects\Accord.NET\framework\Unit Tests\Accord.Tests.Imaging\Resources\blend_net45.png", ImageFormat.Png);
Bitmap image = Accord.Imaging.Image.Clone(Properties.Resources.blend_net45);
#endif
#pragma warning disable 618
double[,] expected = image.ToDoubleMatrix(channel: 0);
double[,] actual = result.ToDoubleMatrix(channel: 0);
Assert.IsTrue(Matrix.IsEqual(expected, actual, atol: 0.1));
#pragma warning restore 618
}