Пример #1
0
        public List <RecognitionResult> RecognizeImages(List <Bitmap> images)
        {
            recognitionProgress = 0;
            isRecognizing       = true;

            var answers = new List <RecognitionResult>();

            for (int i = 0; i < images.Count; ++i)
            {
                var imageToRecognize = new SimpleImage(images[i]);
                var imageData        = imageToRecognize.GetGrayData(0, 0, imageToRecognize.Width, imageToRecognize.Height);
                var sample           = new TextureSample(imageData, false);
                answers.Add(GetBestMatch(sample, new Rectangle(0, 0, imageData.Width, imageData.Height)));
                recognitionProgress += 1.0 * i / images.Count;
            }

            recognitionProgress = 1;
            isRecognizing       = false;
            return(answers);
        }
Пример #2
0
        public RecognitionResult RecognizeImage(Bitmap image, Rectangle region)
        {
            recognitionProgress = 0;
            isRecognizing       = true;

            var imageToRecognize = new SimpleImage(image);

            recognitionProgress = 0.2;

            var imageData = imageToRecognize.GetGrayData(region.X, region.Y,
                                                         region.X + region.Width, region.Y + region.Height);
            var sample = new TextureSample(imageData, false);

            recognitionProgress = 0.8;

            var answer = GetBestMatch(sample, region);

            recognitionProgress = 1;
            isRecognizing       = false;
            return(answer);
        }
Пример #3
0
        private void TeachThread(object parameter)
        {
            TeachThreadParameter input = parameter as TeachThreadParameter;

            if (input == null)
            {
                throw new ArgumentNullException("Неправильный параметр потока.");
            }

            var delta = 1.0 / filesToTeach.Count;

            for (int i = input.From; (i < input.To) && (!isTeachingAborted); ++i)
            {
                try
                {
                    var image     = new SimpleImage(imagesToTeach[i]);
                    var imageData = image.GetGrayData();
                    var lbp       = new LBPCreator(imageData, true, true, false);
                    var glcm      = new GLCMCreator(imageData, true, true, false);
                    AddFeatures(glcm.Feature, lbp.Feature, filesToTeach[i]);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    continue;
                }
                finally
                {
                    lock ((knownFiles as ICollection).SyncRoot)
                    {
                        teachProgress += delta;
                    }
                }
            }
            input.CommonBarrier.SignalAndWait();
        }