コード例 #1
0
        /// <summary>
        /// Calculates the FingerPrint of the LockBitImage
        /// </summary>
        /// <param name="image">The LockBitImage</param>
        /// <returns>A FingerPrint representing this LockBitImage</returns>
        public static ImageFingerPrint CalculateFingerPrint(IImageFrame image)
        {
            var cropWindow = new Size(MACROBLOCK_LENGTH, MACROBLOCK_LENGTH);

            var topLeftPoint = new Point(0, 0);
            var topRightPoint = new Point(image.Width - MACROBLOCK_LENGTH, 0);
            var centerPoint = new Point((image.Width / 2) - (MACROBLOCK_LENGTH / 2), (image.Height / 2) - (MACROBLOCK_LENGTH / 2));
            var bottomLeftPoint = new Point(0, image.Height - MACROBLOCK_LENGTH);
            var bottomRightPoint = new Point(image.Width - MACROBLOCK_LENGTH, image.Height - MACROBLOCK_LENGTH);

            var focusTopLeftPoint = new Point((image.Width / 3) - (MACROBLOCK_LENGTH / 2), (image.Height / 3) - (MACROBLOCK_LENGTH / 2));
            var focusTopRightPoint = new Point((image.Width * 2 / 3) - (MACROBLOCK_LENGTH / 2), (image.Height / 3) - (MACROBLOCK_LENGTH / 2));
            var focusBottomLeftPoint = new Point((image.Width / 3) - (MACROBLOCK_LENGTH / 2), (image.Height * 2 / 3) - (MACROBLOCK_LENGTH / 2));
            var focusBottomRightPoint = new Point((image.Width * 2 / 3) - (MACROBLOCK_LENGTH / 2), (image.Height * 2 / 3) - (MACROBLOCK_LENGTH / 2));

            return new ImageFingerPrint(
                GetMacroblock(image, new Rectangle(topLeftPoint, cropWindow)),
                GetMacroblock(image, new Rectangle(topRightPoint, cropWindow)),
                GetMacroblock(image, new Rectangle(centerPoint, cropWindow)),
                GetMacroblock(image, new Rectangle(bottomLeftPoint, cropWindow)),
                GetMacroblock(image, new Rectangle(bottomRightPoint, cropWindow)),
                GetMacroblock(image, new Rectangle(focusTopLeftPoint, cropWindow)),
                GetMacroblock(image, new Rectangle(focusTopRightPoint, cropWindow)),
                GetMacroblock(image, new Rectangle(focusBottomLeftPoint, cropWindow)),
                GetMacroblock(image, new Rectangle(focusBottomRightPoint, cropWindow))
            );
        }
コード例 #2
0
        /// <summary>
        /// Calculate the SSIM between two IImageFrames
        /// </summary>
        /// <param name="first">The first image</param>
        /// <param name="second">The second image</param>
        /// <returns>The SSIM of two IImageFrames</returns>
        public static double Compute(IImageFrame first, IImageFrame second)
        {
            if (first == null || second == null)
            {
                throw new ArgumentNullException();
            }

            return ComputeSSIM(
                ConvertToGrayscale(first),
                ConvertToGrayscale(second)
            );
        }
コード例 #3
0
 /// <summary>
 /// Create a new isntance of <see cref="FrameReceivedEventArgs"/>
 /// </summary>
 /// <param name="frame">Channel used for transfers</param>
 public FrameReceivedEventArgs(IImageFrame frame)
 {
     this.Frame       = frame;
     this.IsLastFrame = false;
 }
コード例 #4
0
 private static Grid ConvertToGrayscale(IImageFrame bitmap)
 {
     return Grid.Op(
         (i, j) => ConvertColorToGrayscaleDouble(bitmap.GetPixel(i, j)),
         new Grid(bitmap.Width, bitmap.Height)
     );
 }
コード例 #5
0
        /// <summary>
        /// Copies the properties from the other <see cref="IImageFrame"/>.
        /// </summary>
        /// <param name="other">
        /// The other <see cref="IImageFrame"/> to copy the properties from.
        /// </param>
        private void CopyProperties(IImageFrame other)
        {
            base.CopyProperties(other);

            this.MetaData = new ImageFrameMetaData(other.MetaData);
        }
コード例 #6
0
 public static Maybe<Image> TryResizeAndBlurImage(IImageFrame image)
 {
     // Copy image to bitmap
     using (var bitmap = new Bitmap(image.Width, image.Height))
     {
         for (int row = 0; row < image.Height; row++)
         {
             for (int col = 0; col < image.Height; col++)
             {
                 bitmap.SetPixel(col, row, image.GetPixel(col, row));
             }
         }
         return
             from pass1Image in ImageTransformations.TryResizeImage(
                 bitmap,
                 FINGERPRINT_PASS1_WIDTH,
                 (image.Height * FINGERPRINT_PASS1_WIDTH) / image.Width
             )
             from blurredImage in ImageTransformations.TryBlurImage(pass1Image, 5)
             select ImageTransformations.TryResizeImage(
                 blurredImage,
                 FINGERPRINT_WIDTH,
                 (image.Height * FINGERPRINT_WIDTH) / image.Width
             );
     }
 }
コード例 #7
0
        private static Macroblock GetMacroblock(IImageFrame image, Rectangle cropArea)
        {
            Color[,] colorGrid = new Color[cropArea.Width, cropArea.Height];
            int colorGridY = 0;
            foreach (var y in Enumerable.Range(cropArea.Y, cropArea.Height))
            {
                int colorGridX = 0;
                foreach (var x in Enumerable.Range(cropArea.X, cropArea.Width))
                {
                    colorGrid[colorGridY, colorGridX] = image.GetPixel(x, y);
                    colorGridX++;
                }

                colorGridY++;
            }

            return new Macroblock(colorGrid);
        }