public void UseRansacAlgorithm(int iterationsCount = 1000, float r = 5, float R = 700, bool secondError = true)
        {
            var min = GetMinSide();

            r = min * 0.05f;
            R = min * 0.3f;
            RansacTriangle             = Ransac.RansacAlgorithm(ConsistencyNeighbourPairs, iterationsCount, r, R, secondError);
            RansacFilterNeighbourPairs = Ransac.RansacFilterKeyPoint(ConsistencyNeighbourPairs, RansacTriangle, R);
        }
        private Image <Bgr, byte> CreateMargedImage(
            Image <Bgr, byte> firstImage, Image <Bgr, byte> secondImage,
            Dictionary <KeyPoint, KeyPoint> pairs, KeyPairsTriangle ransacTriangle)
        {
            // Marge image.
            var margedImageWidth  = firstImage.Width + secondImage.Width;
            var margedImageHeight = Math.Max(firstImage.Height, secondImage.Height);

            var imageResult = new Image <Bgr, byte>(margedImageWidth, margedImageHeight)
            {
                ROI = new Rectangle(0, 0, firstImage.Width, firstImage.Height)
            };

            firstImage.CopyTo(imageResult);

            imageResult.ROI = new Rectangle(firstImage.Width, 0, secondImage.Width, secondImage.Height);
            secondImage.CopyTo(imageResult);

            imageResult.ROI = Rectangle.Empty;

            // Use Ransac.
            if (ransacTriangle != null)
            {
                var firstTriangle  = ransacTriangle.GetFirstTriangle();
                var secondTriangle = ransacTriangle.GetSecondTriangle();

                var triangleColor = new Bgr(Color.Black).MCvScalar;

                CvInvoke.Line(imageResult, firstTriangle[0], firstTriangle[1], triangleColor, 2);
                CvInvoke.Line(imageResult, firstTriangle[1], firstTriangle[2], triangleColor, 2);
                CvInvoke.Line(imageResult, firstTriangle[2], firstTriangle[0], triangleColor, 2);
                CvInvoke.Line(imageResult, secondTriangle[0].ChangeOffset(firstImage.Width),
                              secondTriangle[1].ChangeOffset(firstImage.Width), triangleColor, 2);
                CvInvoke.Line(imageResult, secondTriangle[1].ChangeOffset(firstImage.Width),
                              secondTriangle[2].ChangeOffset(firstImage.Width), triangleColor, 2);
                CvInvoke.Line(imageResult, secondTriangle[2].ChangeOffset(firstImage.Width),
                              secondTriangle[0].ChangeOffset(firstImage.Width), triangleColor, 2);
            }

            // Draw lines.
            foreach (var _pair in pairs)
            {
                var start  = new Point((int)_pair.Key.X, (int)_pair.Key.Y);
                var second = new Point((int)_pair.Value.X + firstImage.Width, (int)_pair.Value.Y);

                CvInvoke.Line(imageResult, start, second, new Bgr(_pair.Key.Color).MCvScalar, 1);
            }
            return(imageResult);
        }