Exemplo n.º 1
0
        public AsyncOCR(SImage image, frmBabel Form, Action <AsyncOCR> callback = null)
        {
            this.image     = image.Copy();
            this.Form      = Form;
            this.callback += callback;

            if (Properties.Settings.Default.dummyData)
            {
                _bigBox     = OCRBox.DummyBigBox();
                _smallBoxes = OCRBox.DummySmallBoxes();
                _timeStamp  = "[dummy]";
                isDone      = true;
                callback?.Invoke(this);
            }
            else if (image == null)
            {
                _bigBox     = null;
                _smallBoxes = new OCRBox[0];
                _timeStamp  = "[empty]";
                isDone      = true;
                callback?.Invoke(this);
            }
            else
            {
                task = Task.Run(DoOCR);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Extracts each gems rectangle in the image
        /// </summary>
        /// <param name="screenshot">An image of the current playing area (without windowborders)</param>
        /// <param name="gemSlots"></param>
        /// <returns>A two-dimensional array of images in the [row,column] format</returns>
        public Image<Bgr, byte>[,] ExtractGemSlots(Image<Bgr, byte> screenshot, GemSlot[,] gemSlots)
        {
            #if SAVEIMAGES
            string basePath = "abc\\";
            foreach(GemColor color in Enum.GetValues(typeof(GemColor)))
            {
                if (!System.IO.Directory.Exists(basePath + color))
                    System.IO.Directory.CreateDirectory(basePath + color);
            }

            #endif
            Image<Bgr, byte>[,] gemSlotImages = new Image<Bgr, byte>[8,8];
            for (int row = 0; row < 8; row++)
            {
                for (int column = 0; column < 8; column++)
                {
                    Rectangle gemSlotRectangle = gemSlots[row, column].Rectangle;
                    gemSlotImages[row, column] = screenshot.Copy(gemSlotRectangle);
            #if SAVEIMAGES
                    Random rand = new Random();
                    Gem prediction = (new SimpleGemClassifier().ClassifyGem(gemSlotImages[row, column]));
                    gemSlotImages[row, column].Save("abc\\" + prediction.Color.ToString() + "\\" + rand.Next() + "." + row + "." + column + ".png");
            #endif
                }
            }
            return gemSlotImages;
        }
Exemplo n.º 3
0
        public DetectorResult Process(Image<Bgr, byte> rawFrame, Image<Gray, byte> grayFrame)
        {
            grayFrame.PyrDown().PyrUp();
            var processedFrame = rawFrame.Copy();
            Gray cannyThreshold = new Gray(180);
            Gray circleAccumulatorThreshold = new Gray(500);

            CircleF[] circles = grayFrame.HoughCircles(
                cannyThreshold,
                circleAccumulatorThreshold,
                4.0, //Resolution of the accumulator used to detect centers of the circles
                15.0, //min distance
                5, //min radius
                0 //max radius
                )[0]; //Get the circles from the first channel

            foreach (CircleF circle in circles)
            {
                processedFrame.Draw(circle, new Bgr(Color.DarkRed), 1);
            }
            return new DetectorResult() {RawImage = rawFrame, GrayImage = grayFrame, ProcessedImage = processedFrame};
        }
Exemplo n.º 4
0
        public override IDataContainer PreProcess(IDataContainer dataContainer)
        {
            _debugOutputImage = new Image<Rgb, byte>(Width, Height);

            var rgbImage = dataContainer.OfType<RgbImageData>().ToArray();

            if (!rgbImage.Any()) return null;

            _debugOutputImage += rgbImage.First().Image.Copy();

            var devices = dataContainer.OfType<Device>().ToArray();
            //var unknownDevices = dataContainer.OfType<Device>().Where(d => !d.IsIdentified).ToArray();
            var hands = dataContainer.OfType<Hand>().ToArray();

            foreach (var device in devices)
            {
                var polyline = new List<Point>();
                foreach (var point in device.Shape.Points)
                {
                    var x = point.X * Width;
                    var y = point.Y * Height;

                    polyline.Add(new Point((int)x, (int)y));
                }

                var centerX = (int)(device.SmoothedCenter.X / 320 * Width);
                var centerY = (int)(device.SmoothedCenter.Y / 240 * Height);

                _debugOutputImage.DrawPolyline(polyline.ToArray(), true, device.IsIdentified ? Rgbs.Red : Rgbs.White, 5);

                if (device.IsIdentified)
                    _debugOutputImage.Draw(string.Format("Id {0}", device.DeviceId), ref EmguFontBig, new Point(centerX, centerY), Rgbs.Red);
            }

            foreach (var hand in hands)
            {
                var resizedHandSegment = hand.Segment.Resize(_debugOutputImage.Width, _debugOutputImage.Height, INTER.CV_INTER_CUBIC).Mul(255);

                //_debugOutputImage = _debugOutputImage.Copy(resizedHandSegment.Not());
                _debugOutputImage = _debugOutputImage.AddWeighted(resizedHandSegment.Convert<Rgb, byte>(), 1.0, 0.5, 0.0);

                resizedHandSegment.Dispose();

                var point = new Point((int)(hand.RelativeCenter.X * Width), (int)(hand.RelativeCenter.Y * Height));
                var labelPoint = new Point((int)(hand.RelativeCenter.X * Width + 30), (int)(hand.RelativeCenter.Y * Height));

                _debugOutputImage.Draw(new CircleF(point, 10), Rgbs.Red, 6);
                _debugOutputImage.Draw(string.Format("Id {0} (d={1:F0})", hand.Id, hand.Depth), ref EmguFontBig, labelPoint, Rgbs.Red);
            }

            var debugOutputImageCopy = _debugOutputImage.Copy();
            Task.Factory.StartNew(() =>
            {
                var bitmapSource = debugOutputImageCopy.ToBitmapSource(true);
                debugOutputImageCopy.Dispose();
                return bitmapSource;
            }).ContinueWith(t => DebugOutputBitmapSource = t.Result);

            Stage(new RgbImageData(this, "DataRenderer", _debugOutputImage.Copy()));

            if (_videoWriter != null)
                _videoWriter.WriteFrame(_debugOutputImage.Convert<Bgr, byte>());

            _debugOutputImage.Dispose();

            Push();

            return base.PreProcess(dataContainer);
        }
Exemplo n.º 5
0
 public Image<Bgra, byte> Grab(Image<Bgra, byte> windowContents)
 {
     return windowContents.Copy(_rectangle);
 }