/// <summary>
        /// Adds a BitmapVector to the list of vectors created by resizing and averaging all input images into one. 
        /// The dimensions passed are for the output vector, and not the input images.
        /// </summary>
        /// <param name="images">The list of images to make a vector out of.</param>
        /// <param name="width">The width to make the vector.</param>
        /// <param name="height">The height to make the vector.</param>
        /// <param name="information">Any information that you would like to associate with this BitmapVector.</param>
        public void AddBitmapArrayAsOneVector(List<Bitmap> images, int width, int height, string information)
        {
            BitmapVector v = new BitmapVector(images[0], width, height);

            for (int i = 1; i < images.Count; i++)
            {
                v += new BitmapVector(images[i], width, height);
            }

            v /= images.Count;
            v.Information = information;

            Add(v);
        }
        public static BitmapVector LoadFromFile(BinaryReader r)
        {
            int width  = r.ReadInt32();
            int height = r.ReadInt32();

            BitmapVector v = new BitmapVector(width, height);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    v.matrix[x, y] = r.ReadDouble();
                }
            }

            v.Information = r.ReadString();

            return(v);
        }
Exemple #3
0
        public void AddToGroup(BitmapVector v)
        {
            bool added = false;

            for (int i = 0; i < vectors.Count; i++)
            {
                if (vectors[i].Information == v.Information)
                {
                    vectors[i] += v;

                    added = true;
                    break;
                }
            }
            if (!added)
            {
                vectors.Add(v);
            }
        }
Exemple #4
0
        public BitmapVector GetClosestMatch(BitmapVector v)
        {
            if (vectors.Count == 0)
            {
                throw new CaptchaSolverException("There are no patterns loaded to which a sample pattern may be matched!");
            }

            int    index = 0;
            double best  = BitmapVector.RootMeanSquareDistance(vectors[0].Scale(), v.Scale());

            Parallel.For(1, vectors.Count, i =>
            {
                double test = BitmapVector.RootMeanSquareDistance(vectors[i].Scale(), v.Scale());

                if (test < best)
                {
                    best  = test;
                    index = i;
                }
            });

            return(vectors[index]);
        }
        public BitmapVector GetClosestMatchNoScale(BitmapVector v)
        {
            if (vectors.Count == 0)
            {
                throw new CaptchaSolverException("There are no patterns loaded to match a sample pattern to!");
            }

            int index = 0;
            double best = BitmapVector.RootMeanSquareDistance(vectors[0] / Count, v);

            //vectors[0].GetBitmap().Save("getmatch-a--" + index.ToString() + ".bmp");
            //v.GetBitmap().Save("getmatch--b-" + index.ToString() + ".bmp");
            //(vectors[0].Scale() - v.Scale()).GetBitmap().Save("getmatch-ab-" + index.ToString() + ".bmp");

            //for (int i = 1; i < vectors.Count; i++)
            Parallel.For(1, vectors.Count, i =>
            {
                //vectors[i].GetBitmap().Save("getmatch-a--" + i.ToString() + ".bmp");
                //v.GetBitmap().Save("getmatch--b-" + i.ToString() + ".bmp");
                //(vectors[i].Scale() - v.Scale()).GetBitmap().Save("getmatch-ab-" + i.ToString() + ".bmp");

                double test = BitmapVector.RootMeanSquareDistance(vectors[i] / Count, v);

                if (test < best)
                {
                    best = test;
                    index = i;
                }
            });

            return vectors[index];
        }
 public BitmapVector GetClosestMatch(Bitmap image)
 {
     BitmapVector v = new BitmapVector(image, vectors[0].Width, vectors[0].Height);
     return GetClosestMatch(v);
 }
        public BitmapVector Subtract(BitmapVector other)
        {
            BitmapVector sub = this.Clone();

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    sub[x, y] -= other[x, y];
                }
            }

            return sub;
        }
        public BitmapVector Invert()
        {
            BitmapVector copy = new BitmapVector(Width, Height);
            double max = this.Max();

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    copy[x, y] = max - matrix[x, y];
                }
            }

            copy.Information = Information;

            return copy;
        }
        public BitmapVector Clone()
        {
            BitmapVector copy = new BitmapVector(Width, Height);

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    copy[x, y] = matrix[x, y];
                }
            }

            copy.Information = Information;

            return copy;
        }
        public BitmapVector GetClosestMatchNoScale(BitmapVector v)
        {
            if (vectors.Count == 0)
            {
                throw new CaptchaSolverException("There are no patterns loaded to which a sample pattern may be matched!");
            }

            int index = 0;
            double best = BitmapVector.RootMeanSquareDistance(vectors[0] / Count, v);

            Parallel.For(1, vectors.Count, i =>
            {
                double test = BitmapVector.RootMeanSquareDistance(vectors[i] / Count, v);

                if (test < best)
                {
                    best = test;
                    index = i;
                }
            });

            return vectors[index];
        }
        public static BitmapVector LoadFromFile(BinaryReader r)
        {
            int width = r.ReadInt32();
            int height = r.ReadInt32();

            BitmapVector v = new BitmapVector(width, height);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    v.matrix[x, y] = r.ReadDouble();
                }
            }

            v.Information = r.ReadString();

            return v;
        }
        public static BitmapVector ConvertToLinearBitmapVector(DoubleVector v)
        {
            int width = v.Size;
            BitmapVector b = new BitmapVector(width, 1);

            for (int x = 0; x < width; x++)
            {
                b.matrix[x, 0] = v[x];
            }

            return b;
        }
Exemple #13
0
        public BitmapVector GetClosestMatch(Bitmap image)
        {
            BitmapVector v = new BitmapVector(image, vectors[0].Width, vectors[0].Height);

            return(GetClosestMatch(v));
        }
Exemple #14
0
        public void Add(Bitmap image)
        {
            BitmapVector v = new BitmapVector(image, image.Width, image.Height);

            vectors.Add(v);
        }
Exemple #15
0
 public void Add(BitmapVector v)
 {
     vectors.Add(v);
 }
 public void Add(BitmapVector v)
 {
     vectors.Add(v);
 }
 public void Add(Bitmap image)
 {
     BitmapVector v = new BitmapVector(image, image.Width, image.Height);
     vectors.Add(v);
 }
        public static double RootMeanSquareDistance(BitmapVector left, BitmapVector right)
        {
            double value = 0.0;

            for (int x = 0; x < left.Width; x++)
            {
                for (int y = 0; y < left.Height; y++)
                {
                    value += Math.Pow(left.matrix[x, y] - right.matrix[x, y], 2.0);
                }
            }

            return Math.Sqrt(value / (left.Width * left.Height));
        }
        public void AddToGroup(BitmapVector v)
        {
            bool added = false;
            for (int i = 0; i < vectors.Count; i++)
            {
                if (vectors[i].Information == v.Information)
                {
                    vectors[i] += v;

                    added = true;
                    break;
                }
            }
            if (!added)
            {
                vectors.Add(v);
            }
        }
        public BitmapVector Binarize()
        {
            BitmapVector copy = new BitmapVector(Width, Height);
            double max = this.Max();

            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    copy[x, y] = matrix[x, y] >= 0.5 ? 1.0 : 0.0;
                }
            }

            copy.Information = Information;

            return copy;
        }