Exemplo n.º 1
0
        public static Image Go(string path)
        {
            var l = Perfect.ColorFromImg(path);
            var t = ObjToAnother.GetBitmapFromArr(l, 160);

            string pathh = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            t.Save(pathh + "\\he.jpg");

            var hh = Perfect.Gayss(t);

            var cut = Perfect.CuteFunction(hh);

            var miniimg = ObjToAnother.GetBitmapFromArr(cut, 1);

            miniimg.Save(pathh + "\\mini.jpg");

            Bitmap ArrFrame = new Bitmap(miniimg, new Size(50, 50));

            ArrFrame.Save(pathh + "\\frame.jpg");


            Stud.IsInMemory(ArrFrame, "mem.txt", "pairsMemory.txt");


            return(ArrFrame);
        }
Exemplo n.º 2
0
        public static void Write(Bitmap ArrFrame)
        {
            StreamWriter strw = new StreamWriter("mem.txt", true);
            var          okgo = ObjToAnother.GetArrFromBMP(ArrFrame);

            for (var i = 0; i < okgo.GetLength(0); i++)
            {
                for (var j = 0; j < okgo.GetLength(1); j++)
                {
                    strw.Write(okgo[j, i]);
                }
                //strw.WriteLine();
            }
            strw.WriteLine();
            strw.Close();
        }
Exemplo n.º 3
0
        public static double[,] Gayss(Bitmap bmp)
        {
            var    inp = ObjToAnother.GetArrFromBMP(bmp);
            var    a = inp.GetLength(0);
            var    b = inp.GetLength(1);
            var    res = new double[a, b];
            int    x, y;
            double pointColor = 0;

            for (var i = 0; i < a; i++)
            {
                for (var j = 0; j < b; j++)
                {
                    int count = 0;
                    var t     = new double[9];
                    if (i == 0 || j == 0 || i == a - 1 || j == b - 1)
                    {
                        for (x = 0; x <= 1; x++)
                        {
                            for (y = 0; y <= 1; y++)
                            {
                                t[count] = 1;
                                count++;
                            }
                        }
                    }
                    else
                    {
                        for (x = -1; x <= 1; x++)
                        {
                            for (y = -1; y <= 1; y++)
                            {
                                t[count] = inp[i + x, j + y];
                                count++;
                            }
                        }
                    }
                    pointColor = t[0] + 2 * t[1] + t[2] + 2 * t[3] + 4 * t[4] + 2 * t[5] + t[6] + 2 * t[7] + t[8];
                    res[i, j]  = pointColor / 8;
                }
            }
            return(res);
        }
Exemplo n.º 4
0
        public static void IsInMemory(Bitmap bmp, string name, string pairsName)
        {
            var isit = true;

            //var isInMem = true;
            if (!File.Exists(name))
            {
                File.Create(name).Close();
            }
            if (!File.Exists(pairsName))
            {
                File.Create(pairsName).Close();
            }
            string[] str = File.ReadAllLines(name);
            Dictionary <int, string> memory = new Dictionary <int, string>();
            var arr = ObjToAnother.GetArrFromBMP(bmp);

            var it = new double[str.Length];

            for (var i = 0; i < str.Length; i++)
            {
                char[] t = str[i].ToCharArray();
                int    h = 0, w = 0;
                for (var j = 0; j < t.Length; j++)
                {
                    if (arr[w, h] == Double.Parse(t[j].ToString()))
                    {
                        it[i]++;
                    }
                    if (w == 49)
                    {
                        h++;
                        w = -1;
                    }
                    w++;
                }
                Console.WriteLine("----------------" + it[i] / 25 + "%-----------------------------------");
            }
            string[] pairs = File.ReadAllLines(pairsName);
            for (var j = 0; j < pairs.Length; j++)
            {
                char[] temp = pairs[j].ToCharArray();
                if (temp.Length != 0)
                {
                    //var i = 0;
                    //for (var i = 0; i < pairs.Length; i++)
                    //{
                    string s = "";
                    for (var i = 2; i < temp.Length; i++)
                    {
                        s += temp[i];
                    }
                    memory.Add(Int32.Parse(temp[0].ToString()), s);

                    //}
                }
            }

            if (it.Length == 0)
            {
                FileRW.Write(bmp);
                FileRW.Read("mem.txt");
                Console.WriteLine("Memory if empty. What is it?");
                var s = Console.ReadLine();
                memory.Add(0, s);
                FileRW.Write(0, s, pairsName);
                isit = false;
            }
            else
            {
                var counter = 0;
                for (var i = 0; i < it.Length; i++)
                {
                    if (it[i] / 2500 > 0.85)
                    {
                        Console.WriteLine("It is " + memory[i]);
                        isit = false;
                        break;
                    }
                    else
                    {
                        counter++;//FileRW.Read("mem.txt");
                    }
                }
                if (counter == it.Length)
                {
                    Console.WriteLine("Unknown symbol. What is it?");
                    var s = Console.ReadLine();
                    memory.Add(it.Length, s);
                    FileRW.Write(it.Length, s, pairsName);
                }
            }

            if (isit)
            {
                FileRW.Write(bmp);
                FileRW.Read("mem.txt");
            }
        }