Esempio n. 1
0
        private static void CheckOne(LensDistortionMapping correction, Vector2 distorted)
        {
            Vector2 corrected   = correction.GetCorrected(distorted);
            Vector2 redistorted = correction.GetDistorted(corrected);

            Assert.IsTrue(distorted.Equals(redistorted, .05));
        }
Esempio n. 2
0
 public void TestTransforms()
 {
     LensDistortionMapping correction = new LensDistortionMapping(640, 480, k1_RadialDistortion: .000001);
     CheckOne(correction, new Vector2(630, 470));
     CheckOne(correction, new Vector2(10, 20));
     CheckOne(correction, new Vector2(1, 2));
     CheckOne(correction, new Vector2(320, 240));
 }
Esempio n. 3
0
        public void TestTransforms()
        {
            LensDistortionMapping correction = new LensDistortionMapping(640, 480, k1_RadialDistortion: .000001);

            CheckOne(correction, new Vector2(630, 470));
            CheckOne(correction, new Vector2(10, 20));
            CheckOne(correction, new Vector2(1, 2));
            CheckOne(correction, new Vector2(320, 240));
        }
Esempio n. 4
0
        private void CreateInverseImageMappingCache(LensDistortionMapping correctionForLens)
        {
#if MULTI_THREAD
            System.Threading.Tasks.Parallel.For(0, height, y => //  
#else
            for (int y = 0; y < height; y++)
#endif
            {
                for (int x = 0; x < width; x++)
                {
                    int offsetToFirstPixelForBlend = y * width * 4 + x * 4;

                    Vector2 distortedVector = new Vector2(x, y);
                    Vector2 correctedVector = correctionForLens.GetDistorted(distortedVector);
                    if (correctedVector.x < 0 || correctedVector.x >= width - 1 ||
                        correctedVector.y < 0 || correctedVector.y >= height - 1)
                    {
                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 0] = 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 0] = blendFractionDenominator;

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 1] = 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 1] = 0;

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 2] = 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 2] = 0;

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 3] = 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 3] = 0;
                    }
                    else
                    {
                        Point2D correctedPoint = new Point2D((int)correctedVector.x, (int)correctedVector.y);
                        double xFraction = correctedVector.x - correctedPoint.x;
                        double yFraction = correctedVector.y - correctedPoint.y;
                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 0] = (correctedPoint.y + 0) * width + correctedPoint.x + 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 0] = (int)(blendFractionDenominator * (1-xFraction)*(1-yFraction));

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 1] = (correctedPoint.y + 0) * width + correctedPoint.x + 1;
                        bilinearWeightTable[y * width * 4 + x * 4 + 1] = (int)(blendFractionDenominator * (xFraction) * (1 - yFraction));

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 2] = (correctedPoint.y + 1) * width + correctedPoint.x + 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 2] = (int)(blendFractionDenominator * (1 - xFraction) * (yFraction));

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 3] = (correctedPoint.y + 1) * width + correctedPoint.x + 1;
                        bilinearWeightTable[y * width * 4 + x * 4 + 3] = (int)(blendFractionDenominator * (xFraction) * (yFraction));
                    }
                }
            }
#if MULTI_THREAD
);
#endif
        }
Esempio n. 5
0
        public ImageCorrection(int width, int height, bool doBilinearFilter = true, LensDistortionMapping correctionForLens = null)
        {
            DoBilinearFilter = true;
            this.width = width;
            this.height = height;

            bilinearDistortedToRectifideOffsetTable = new int[width * height * 4];
            bilinearWeightTable = new int[width * height * 4];

            if (correctionForLens != null)
            {
                CreateInverseImageMappingCache(correctionForLens);
            }
        }
Esempio n. 6
0
        private void CreateInverseImageMappingCache(LensDistortionMapping correctionForLens)
        {
#if MULTI_THREAD
            System.Threading.Tasks.Parallel.For(0, height, y => //  
#else
            for (int y = 0; y < height; y++)
#endif
            {
                for (int x = 0; x < width; x++)
                {
                    int offsetToFirstPixelForBlend = y * width * 4 + x * 4;

                    Vector2 distortedVector = new Vector2(x, y);
                    Vector2 correctedVector = correctionForLens.GetDistorted(distortedVector);
                    if (correctedVector.x < 0 || correctedVector.x >= width - 1 ||
                        correctedVector.y < 0 || correctedVector.y >= height - 1)
                    {
                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 0] = 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 0] = blendFractionDenominator;

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 1] = 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 1] = 0;

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 2] = 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 2] = 0;

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 3] = 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 3] = 0;
                    }
                    else
                    {
                        Point2D correctedPoint = new Point2D((int)correctedVector.x, (int)correctedVector.y);
                        double xFraction = correctedVector.x - correctedPoint.x;
                        double yFraction = correctedVector.y - correctedPoint.y;
                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 0] = (correctedPoint.y + 0) * width + correctedPoint.x + 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 0] = (int)(blendFractionDenominator * (1-xFraction)*(1-yFraction));

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 1] = (correctedPoint.y + 0) * width + correctedPoint.x + 1;
                        bilinearWeightTable[y * width * 4 + x * 4 + 1] = (int)(blendFractionDenominator * (xFraction) * (1 - yFraction));

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 2] = (correctedPoint.y + 1) * width + correctedPoint.x + 0;
                        bilinearWeightTable[y * width * 4 + x * 4 + 2] = (int)(blendFractionDenominator * (1 - xFraction) * (yFraction));

                        bilinearDistortedToRectifideOffsetTable[offsetToFirstPixelForBlend + 3] = (correctedPoint.y + 1) * width + correctedPoint.x + 1;
                        bilinearWeightTable[y * width * 4 + x * 4 + 3] = (int)(blendFractionDenominator * (xFraction) * (yFraction));
                    }
                }
            }
Esempio n. 7
0
 private static void CheckOne(LensDistortionMapping correction, Vector2 distorted)
 {
     Vector2 corrected = correction.GetCorrected(distorted);
     Vector2 redistorted = correction.GetDistorted(corrected);
     Assert.IsTrue(distorted.Equals(redistorted, .05));
 }