Esempio n. 1
0
        public void ShouldSerializeImagePattern()
        {
            var expected = "{" +
                           "\"Format\":\"2BPP GB\"," +
                           "\"Height\":96," +
                           "\"Palette\":[{\"Alpha\":255,\"Red\":0,\"Green\":0,\"Blue\":0,\"Hue\":0.0},{\"Alpha\":255,\"Red\":8,\"Green\":82,\"Blue\":66,\"Hue\":167.02704},{\"Alpha\":255,\"Red\":90,\"Green\":140,\"Blue\":255,\"Hue\":221.8182},{\"Alpha\":255,\"Red\":239,\"Green\":239,\"Blue\":239,\"Hue\":0.0}]," +
                           "\"TilePattern\":null," +
                           "\"Width\":128}";

            var parameters = new ImagePattern()
            {
                Format = "2BPP GB",
                Height = 96,
                Width  = 128,
            };

            parameters.Palette.Add(new SKColor(0x00, 0x00, 0x00, 0xFF));
            parameters.Palette.Add(new SKColor(0x08, 0x52, 0x42, 0xFF));
            parameters.Palette.Add(new SKColor(0x5A, 0x8C, 0xFF, 0xFF));
            parameters.Palette.Add(new SKColor(0xEF, 0xEF, 0xEF, 0xFF));

            var result = JsonConvert.SerializeObject(parameters);

            Assert.That(expected, Is.EqualTo(result));
        }
Esempio n. 2
0
        /// <summary>Locate and image in the screen and return the coordinates (X, Y, Width, height) of the image</summary>
        /// <param name="path">Path of the image to look for</param>
        /// <param name="attempts">Amount of tries to look for the image in the screen</param>
        /// <param name="region">Region of the screen to look for the image, for more details look for ScreenRegions class</param>
        /// <param name="waitInterval">Amount of time in milliseconds to wait for each attempts before starting to look for the image again</param>
        public static Rect Find(string path, int attempts = 0, Rect region = null, int waitInterval = 1000)
        {
            ValidateImage(path);
            for (int i = 0; i <= attempts; i++)
            {
                using (ImagePattern pattern = new ImagePattern(new Bitmap(Bitmap.FromFile(path))))
                {
                    Rectangle currentRegion = region == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(region);

                    Area area = new Area(currentRegion);

                    Quellatalo.Nin.TheEyes.Match match = area.Find(pattern);
                    if (match == null)
                    {
                        Thread.Sleep(waitInterval);
                        continue;
                    }
                    else
                    {
                        return(region == null?RectangleToRect(match.Rectangle) : FixCoordinates(currentRegion, match.Rectangle));
                    }
                }
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取图片地址的第一次匹配结果
        /// </summary>
        /// <param name="html">图片页的HTML</param>
        /// <param name="groupUrl">图组地址</param>
        /// <returns></returns>
        private IEnumerable <string> GetImageUrls(string html, string groupUrl)
        {
            ImagePattern.CheckNotNull("ImagePattern");

            List <string> matches = html.Matches(ImagePattern).ToList();

            return(matches.Select(m => GetImageUrl(m, groupUrl)).ToList());
        }
Esempio n. 4
0
        public void ShouldConvertDataToPlanar2BPPImage()
        {
            using (var stream = new MemoryStream(this.hexData))
            {
                var plan = new List <List <short> >()
                {
                    new List <short>()
                    {
                        0, 0, 0, 0, 0, 0, 0, 0,
                        2, 2, 2, 2, 2, 2, 2, 2,
                        4, 4, 4, 4, 4, 4, 4, 4,
                        6, 6, 6, 6, 6, 6, 6, 6,
                        8, 8, 8, 8, 8, 8, 8, 8,
                        10, 10, 10, 10, 10, 10, 10, 10,
                        12, 12, 12, 12, 12, 12, 12, 12,
                        14, 14, 14, 14, 14, 14, 14, 14,
                    },
                    new List <short>()
                    {
                        1, 1, 1, 1, 1, 1, 1, 1,
                        3, 3, 3, 3, 3, 3, 3, 3,
                        5, 5, 5, 5, 5, 5, 5, 5,
                        7, 7, 7, 7, 7, 7, 7, 7,
                        9, 9, 9, 9, 9, 9, 9, 9,
                        11, 11, 11, 11, 11, 11, 11, 11,
                        13, 13, 13, 13, 13, 13, 13, 13,
                        15, 15, 15, 15, 15, 15, 15, 15,
                    },
                };

                var parameters = new ImagePattern()
                {
                    Format      = "Planar-2BPP",
                    Height      = 8,
                    Width       = 8,
                    TilePattern = new TilePattern(plan)
                    {
                        Height     = 8,
                        Interleave = true,
                        Order      = EnumTileOrder.Planar,
                        Size       = 16,
                        Width      = 8,
                    },
                };

                var converter = new Planar2BPP();

                var bitmap = converter.Convert(stream, parameters);

                Assert.That(this.imageData, Is.EqualTo(bitmap.Pixels));
            }
        }
Esempio n. 5
0
        private void ListViewItem_PreviewMouseDoubleClick(object sender, RoutedEventArgs e)
        {
            var item = sender as ListViewItem;

            if (item != null)
            {
                ImagePattern mySelectedItem = item.Content as ImagePattern;
                if (mySelectedItem != null)
                {
                    ImageFilePatternTextBox.Text += mySelectedItem.Key;
                }
            }
        }
Esempio n. 6
0
        private void ListViewItem_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var item = sender as ListViewItem;

            if (item != null)
            {
                ImagePattern mySelectedItem = item.Content as ImagePattern;
                if (mySelectedItem != null)
                {
                    DragDrop.DoDragDrop(ImagePatternList, mySelectedItem.Key, DragDropEffects.Copy);
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 指定した形のサムネイルのみを選択します。
        /// </summary>
        /// <param name="pattern">イメージの形を表すImagePattern列挙型の内の1つ。</param>
        public void SelectImageByPattern(ImagePattern pattern)
        {
            // 選択アイテムをクリア
            this.SelectedIndices.Clear();
            if (!this.VirtualMode)
            {
                this.SelectedItems.Clear();
            }

            foreach (var item in this.itemList)
            {
                if (item.ImagePattern == pattern)
                {
                    this.SelectedIndices.Add(item.ItemListIndex);
                }
            }
        }
Esempio n. 8
0
        /// <summary>Locate all ocurrences of and image in the screen</summary>
        /// <param name="image">image to look for</param>
        /// <param name="region">Region of the screen to look for the image, for more details look for ScreenRegions class</param>
        public static IEnumerable <Rect> FindAll(Bitmap image, Rect region = null)
        {
            ICollection <Rect> results = new List <Rect>();

            using (ImagePattern pattern = new ImagePattern(image))
            {
                Rectangle currentRegion = region == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(region);

                Area area = new Area(currentRegion);
                IEnumerable <Quellatalo.Nin.TheEyes.Match> matches = area.FindAll(pattern);
                foreach (Quellatalo.Nin.TheEyes.Match match in matches)
                {
                    results.Add(region == null ? RectangleToRect(match.Rectangle) : FixCoordinates(currentRegion, match.Rectangle));
                }
                return(results);
            }
        }
Esempio n. 9
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var             view       = new RecognizerView();
            IMessageService msgService = new DialogMessageService();

            INeuralNetwork  network = new NeuraNet();
            INetworkManager manager = new NeuraNetFileManager();

            var patternManager = new ImagePatternManager();
            var pattern        = new ImagePattern(7, 5, new SmileyMap());

            var presenter = new RecognizerPresenter(view, msgService, network, manager, patternManager, pattern);

            Application.Run(view);
        }
Esempio n. 10
0
        /// <summary>
        /// Предоставляет класс Presenter.
        /// </summary>
        /// <param name="mainView">Объект представления</param>
        /// <param name="messageService">Объект отображения оповещений</param>
        /// <param name="network">Объект нейронной сети</param>
        /// <param name="manager">Объект для управления загрузкой / сохранением нейронной сети</param>
        /// <param name="trainsetManager">Объект для получени и обработки обучающей выборки</param>
        /// <param name="pattern">Объект представляющий структуру паттерна</param>
        public RecognizerPresenter(IRecognizerView mainView, IMessageService messageService, INeuralNetwork network, INetworkManager manager, ITrainsetManager <Image, ImagePattern> trainsetManager, ImagePattern pattern)
        {
            this.view            = mainView;
            this.messageService  = messageService;
            this.network         = network;
            this.manager         = manager;
            this.trainsetManager = trainsetManager;
            this.pattern         = pattern;

            view.OpenTrainSetClick += View_OpenTrainSetClick;
            view.LoadNetworkClick  += View_LoadNetworkClick;
            view.SaveNetworkClick  += View_SaveNetworkClick;
            view.RecognizeClick    += View_RecognizeClick;
            view.TrainNetworkClick += View_TrainNetworkClick;
            view.BeforeLoad        += View_BeforeLoad;

            network.EpochTrained  += Network_EpochTrained;
            network.OnTrainingEnd += Network_OnTrainingEnd;
        }
Esempio n. 11
0
        /// <summary>Locate and image in the screen and return true if the image is found</summary>
        /// <param name="image">image to look for</param>
        /// <param name="attempts">Amount of tries to look for the image in the screen</param>
        /// <param name="region">Region of the screen to look for the image, for more details look for ScreenRegions class</param>
        /// <param name="waitInterval">Amount of time in milliseconds to wait for each attempts before starting to look for the image again</param>
        public static bool Exist(Bitmap image, int attempts = 0, Rect region = null, int waitInterval = 1000)
        {
            for (int i = 0; i <= attempts; i++)
            {
                using (ImagePattern pattern = new ImagePattern(new Bitmap(image)))
                {
                    Rectangle currentRegion = region == null?RectToRectangle(ScreenRegions.Complete()) : RectToRectangle(region);

                    Area area = new Area(currentRegion);

                    Quellatalo.Nin.TheEyes.Match match = area.Find(pattern);
                    if (match == null)
                    {
                        Thread.Sleep(waitInterval);
                        continue;
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Esempio n. 12
0
        public void ShouldConvertPlanar2BPPImageToData()
        {
            var plan = new List <List <short> >()
            {
                new List <short>()
                {
                    0, 0, 0, 0, 0, 0, 0, 0,
                    2, 2, 2, 2, 2, 2, 2, 2,
                    4, 4, 4, 4, 4, 4, 4, 4,
                    6, 6, 6, 6, 6, 6, 6, 6,
                    8, 8, 8, 8, 8, 8, 8, 8,
                    10, 10, 10, 10, 10, 10, 10, 10,
                    12, 12, 12, 12, 12, 12, 12, 12,
                    14, 14, 14, 14, 14, 14, 14, 14,
                },
                new List <short>()
                {
                    1, 1, 1, 1, 1, 1, 1, 1,
                    3, 3, 3, 3, 3, 3, 3, 3,
                    5, 5, 5, 5, 5, 5, 5, 5,
                    7, 7, 7, 7, 7, 7, 7, 7,
                    9, 9, 9, 9, 9, 9, 9, 9,
                    11, 11, 11, 11, 11, 11, 11, 11,
                    13, 13, 13, 13, 13, 13, 13, 13,
                    15, 15, 15, 15, 15, 15, 15, 15,
                },
            };

            var parameters = new ImagePattern()
            {
                Format      = "Planar-2BPP",
                Height      = 8,
                Width       = 8,
                TilePattern = new TilePattern(plan)
                {
                    Height     = 8,
                    Interleave = true,
                    Order      = EnumTileOrder.Planar,
                    Size       = 16,
                    Width      = 8,
                },
            };

            var imageInfo = new SKImageInfo(parameters.Width, parameters.Height, SKColorType.Rgba8888);

            var bitmap = new SKBitmap(imageInfo);

            var pixels = bitmap.Pixels;
            int i      = 0;

            foreach (var color in this.imageData)
            {
                pixels[i++] = color;
            }

            bitmap.Pixels = pixels;

            var converter = new Planar2BPP();

            var dataStream = converter.ConvertBack(bitmap, parameters);

            Assert.That(this.hexData, Is.EqualTo(dataStream.ToArray()));
        }
Esempio n. 13
0
    /// <summary>
    /// Loads the database files.
    /// </summary>
    /// <returns>A value indicating whether the database files are loaded or not.</returns>
    public bool LoadDatabaseFiles()
    {
        // Clear the image pattern list
        this.ImagePatterns?.Clear();

        // Close the files if opened
        if (this.imageFileOpen)
        {
            this.loadImageFileStream?.Close();
            this.imageFileOpen = false;
        }

        if (this.labelFileOpen)
        {
            this.loadLabelFileStream?.Close();
            this.labelFileOpen = false;
        }

        // Load the image files
        if (!this.GetImageFileHeader())
        {
            MessageBox.Show("Can not open image file");
            this.imageFileName = null;
            this.imageFileOpen = false;
            this.DatabaseReady = false;
            return(false);
        }

        if (!this.GetLabelFileHeader())
        {
            MessageBox.Show("Can not open label file");
            this.labelFileName = null;
            this.labelFileOpen = false;
            this.DatabaseReady = false;
            return(false);
        }

        // Check the value if the image file and label file have been opened successfully
        if (this.labelFileBeginning.Items != this.imageFileBeginning.Items)
        {
            MessageBox.Show("Item numbers are different");
            this.CloseDatabaseFiles();
            this.DatabaseReady = false;
            return(false);
        }

        this.ImagePatterns             = new List <ImagePattern>(this.imageFileBeginning.Items);
        this.randomizedPatternSequence = new int[this.imageFileBeginning.Items];

        for (var i = 0; i < this.imageFileBeginning.Items; i++)
        {
            var patternArray = new byte[SystemGlobals.ImageSize * SystemGlobals.ImageSize];
            var imagePattern = new ImagePattern();
            this.GetNextPattern(patternArray, out var label, true);
            imagePattern.Pattern = patternArray;
            imagePattern.Label   = label;
            this.ImagePatterns.Add(imagePattern);
        }

        this.DatabaseReady = true;
        this.CloseDatabaseFiles();
        return(true);
    }