예제 #1
0
        /// <summary>
        /// Compare if four points polygon is inside or outside in Rectangle(0,0, width, height)
        /// </summary>
        /// <param name="FourPoints">Four points</param>
        /// <param name="width">The width of rectangle</param>
        /// <param name="height">The height of rectangle</param>
        /// <returns>True if is outside. False if is inside</returns>
        public bool CompareTwoRetangle(List <Point3D> FourPoints, int width, int height)
        {
            double RightX = RemapPixels.Max4(FourPoints[0].X, FourPoints[1].X, FourPoints[2].X, FourPoints[3].X);
            double LeftX  = RemapPixels.Min4(FourPoints[0].X, FourPoints[1].X, FourPoints[2].X, FourPoints[3].X);
            double UpY    = RemapPixels.Min4(FourPoints[0].Y, FourPoints[1].Y, FourPoints[2].Y, FourPoints[3].Y);
            double DownY  = RemapPixels.Max4(FourPoints[0].Y, FourPoints[1].Y, FourPoints[2].Y, FourPoints[3].Y);

            if ((LeftX < 0) || (RightX > width) || (UpY < 0) || (DownY > height))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        private void RecalculateColor(Bitmap Original, Bitmap Destination, List <List <Point3D> > HomographySecondToFirst)
        {
            //Recalculate new color of the pixel.
            LockBitmap SecondBmpLock = new LockBitmap(Original);

            SecondBmpLock.LockBits();
            LockBitmap SecondBmpResultLock = new LockBitmap(Destination);

            SecondBmpResultLock.LockBits();

            int widthSecondOriginal  = Original.Width;
            int heightSecondOriginal = Original.Height;

            ProgBar.Maximum = HomographySecondToFirst.Count;
            ProgBar.Minimum = 0;
            ProgBar.Step    = 1;
            ProgBar.Value   = 0;
            for (int j = 0; j < HomographySecondToFirst.Count - 2; j++)
            {
                for (int i = 0; i < HomographySecondToFirst[j].Count - 2; i++)
                {
                    //Surrounded pixel from Points
                    List <Point3D> currList = new List <Point3D>();
                    currList.Add(HomographySecondToFirst[j][i]);
                    currList.Add(HomographySecondToFirst[j][i + 1]);
                    currList.Add(HomographySecondToFirst[j + 1][i + 1]);
                    currList.Add(HomographySecondToFirst[j + 1][i]);

                    // Only if the distorted polygon is inside the bitmap
                    if (!CompareTwoRetangle(currList, widthSecondOriginal, heightSecondOriginal))
                    {
                        Color c = RemapPixels.RecalcPixelColor(currList, SecondBmpLock, widthSecondOriginal, heightSecondOriginal);
                        SecondBmpResultLock.SetPixel(i, j, c);
                    }
                }
                ProgBar.PerformStep();
            }

            SecondBmpLock.UnlockBits();
            SecondBmpResultLock.UnlockBits();
        }