Exemple #1
0
        private void Highlight_Click(object sender, RoutedEventArgs e)
        {
            var Image       = ModelItem.GetValue <string>("Image");
            var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
            var b           = new System.Drawing.Bitmap(stream);
            var Threshold   = ModelItem.GetValue <double>("Threshold");
            var CompareGray = ModelItem.GetValue <bool>("CompareGray");
            var Processname = ModelItem.GetValue <string>("Processname");
            var limit       = ModelItem.GetValue <Rectangle>("Limit");

            if (Threshold < 0.5)
            {
                Threshold = 0.8;
            }

            var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);

            if (stream != null)
            {
                stream.Dispose();
            }
            stream = null;
            b.Dispose();
            b = null;

            foreach (var r in matches)
            {
                var element = new ImageElement(r);
                element.Highlight(false, System.Drawing.Color.PaleGreen, TimeSpan.FromSeconds(1));
            }
        }
Exemple #2
0
        private void Highlight_Click(object sender, RoutedEventArgs e)
        {
            var    image = ImageString;
            Bitmap b     = Task.Run(() =>
            {
                return(Interfaces.Image.Util.LoadBitmap(image));
            }).Result;

            using (b)
            {
                var Threshold   = ModelItem.GetValue <double>("Threshold");
                var CompareGray = ModelItem.GetValue <bool>("CompareGray");
                var Processname = ModelItem.GetValue <string>("Processname");
                var limit       = ModelItem.GetValue <Rectangle>("Limit");
                if (Threshold < 0.5)
                {
                    Threshold = 0.8;
                }
                var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                foreach (var r in matches)
                {
                    var element = new ImageElement(r);
                    element.Highlight(false, System.Drawing.Color.PaleGreen, TimeSpan.FromSeconds(1));
                }
            }
        }
Exemple #3
0
        private async void btn_Select(object sender, RoutedEventArgs e)
        {
            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    break;
                }
                loadFrom = loadFrom.Parent;
            }
            var Image       = loadFrom.GetValue <string>("Image");
            var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
            var b           = new System.Drawing.Bitmap(stream);
            var Threshold   = loadFrom.GetValue <double>("Threshold");
            var CompareGray = loadFrom.GetValue <bool>("CompareGray");
            var Processname = loadFrom.GetValue <string>("Processname");
            var limit       = loadFrom.GetValue <Rectangle>("Limit");

            if (Threshold < 0.5)
            {
                Threshold = 0.8;
            }

            Interfaces.GenericTools.Minimize();
            System.Threading.Thread.Sleep(100);
            var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);

            if (matches.Count() == 0)
            {
                Interfaces.GenericTools.Restore();
                return;
            }
            var match = matches[0];

            Rectangle rect = Rectangle.Empty;

            using (Interfaces.Overlay.OverlayWindow _overlayWindow = new Interfaces.Overlay.OverlayWindow(true))
            {
                _overlayWindow.BackColor = System.Drawing.Color.Blue;
                _overlayWindow.Visible   = true;
                _overlayWindow.Bounds    = match;
                _overlayWindow.TopMost   = true;
                rect = await getrectangle.GetitAsync();
            }

            ModelItem.Properties["OffsetX"].SetValue(new System.Activities.InArgument <int>(rect.X - match.X));
            ModelItem.Properties["OffsetY"].SetValue(new System.Activities.InArgument <int>(rect.Y - match.Y));
            ModelItem.Properties["Width"].SetValue(new System.Activities.InArgument <int>(rect.Width));
            ModelItem.Properties["Height"].SetValue(new System.Activities.InArgument <int>(rect.Height));
            Interfaces.GenericTools.Restore();
        }
Exemple #4
0
        private List <ImageElement> getBatch(int minresults, int maxresults, Double Threshold, string Processname, TimeSpan Timeout, bool CompareGray, Rectangle limit)
        {
            var          result = new List <ImageElement>();
            Bitmap       b      = null;
            MemoryStream stream = null;

            if (System.Text.RegularExpressions.Regex.Match(Image, "[a-f0-9]{24}").Success)
            {
                b = Task.Run(() =>
                {
                    return(Interfaces.Image.Util.LoadBitmap(Image));
                }).Result;
            }
            else
            {
                stream = new MemoryStream(Convert.FromBase64String(Image));
                b      = new Bitmap(stream);
            }

            var matches = ImageEvent.waitFor(b, Threshold, Processname, Timeout, CompareGray, limit);

            if (matches.Count() > maxresults)
            {
                matches = matches.Take(maxresults).ToArray();
            }
            if (Timeout.TotalMilliseconds > 100)
            {
                if (matches.Length == 0)
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                    b.Dispose();
                    b = null;
                    return(result);
                }
            }
            if (stream != null)
            {
                stream.Dispose();
            }
            b.Dispose();
            b = null;
            foreach (var r in matches)
            {
                result.Add(new ImageElement(r));
            }
            if (result.Count() < minresults)
            {
                Log.Selector(string.Format("Image.GetElement::Failed locating " + minresults + " item(s)"));
                throw new ElementNotFoundException("Failed locating " + minresults + " item(s)");
            }
            return(result);
        }
Exemple #5
0
        private List <ImageElement> getBatch(int maxresults, Double Threshold, string Processname, TimeSpan Timeout, bool CompareGray, Rectangle limit)
        {
            var          result = new List <ImageElement>();
            Bitmap       b      = null;
            MemoryStream stream = null;

            if (System.Text.RegularExpressions.Regex.Match(Image, "[a-f0-9]{24}").Success)
            {
                // b = image.util.loadWorkflowImage(Image);
            }
            else
            {
                stream = new MemoryStream(Convert.FromBase64String(Image));
                b      = new Bitmap(stream);
            }

            var matches = ImageEvent.waitFor(b, Threshold, Processname, Timeout, CompareGray, limit);

            if (matches.Count() > maxresults)
            {
                matches = matches.Take(maxresults).ToArray();
            }
            if (Timeout.TotalMilliseconds > 100)
            {
                if (matches.Length == 0)
                {
                    if (stream != null)
                    {
                        stream.Dispose();
                    }
                    b.Dispose();
                    b = null;
                    return(result);
                }
            }
            if (stream != null)
            {
                stream.Dispose();
            }
            b.Dispose();
            b = null;
            foreach (var r in matches)
            {
                result.Add(new ImageElement(r));
            }

            // Log.Debug("getBatch,count: " + result.Count());
            // _Results.AddRange(result);
            return(result);
        }
Exemple #6
0
        public static Rectangle[] waitFor(Bitmap Image, Double Threshold, String Processname, TimeSpan TimeOut, bool CompareGray, Rectangle Limit)
        {
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            var me = new ImageEvent();

            me.limit       = Limit;
            me.Processname = Processname;
            //util.RemoveNoise(ref Image);
            //rpaactivities.image.util.showImage(Image);
            //me.template = new Image<Bgr, Byte>(Image);
            // rpaactivities.image.util.saveImage(Image, "waitFor-Image");

            me.template = Image;

            me.CompareGray = CompareGray;
            me.threshold   = Threshold;
            me.running     = true;
            if (me.findMatch())
            {
                return(me.results);
            }

            if (TimeOut.TotalMilliseconds < 100)
            {
                return(me.results);
            }
            me.timer           = new System.Timers.Timer();
            me.timer.Elapsed  += new System.Timers.ElapsedEventHandler(me.onElapsed);
            me.timer.AutoReset = true;
            me.timer.Interval  = 100;
            me.timer.Start();

            me.waitHandle = new System.Threading.AutoResetEvent(false);
            me.waitHandle.WaitOne(TimeOut);
            me.running = false;
            me.timer.Stop();
            return(me.results);
        }
        private async Task <Rectangle> GetBaseRectangle()
        {
            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            var pp = ModelItem.Properties["Element"];

            if (pp.IsSet)
            {
                while (loadFrom.Parent != null)
                {
                    var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                    if (p != null)
                    {
                        loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                        break;
                    }
                    if (loadFrom.ItemType == typeof(GetText))
                    {
                        gettext = loadFrom;
                    }
                    loadFrom = loadFrom.Parent;
                }
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
                match = element.Rectangle;
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    match = await getrectangle.GetitAsync();

                    tip.Close();
                    tip = null;
                }
            }
            else if (match.IsEmpty)
            {
                var image = loadFrom.GetValue <string>("Image");
                if (!string.IsNullOrEmpty(image))
                {
                    Bitmap b = Task.Run(() => {
                        return(Interfaces.Image.Util.LoadBitmap(image));
                    }).Result;
                    using (b)
                    {
                        var Threshold   = loadFrom.GetValue <double>("Threshold");
                        var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                        var Processname = loadFrom.GetValue <string>("Processname");
                        var limit       = loadFrom.GetValue <Rectangle>("Limit");
                        if (Threshold < 0.5)
                        {
                            Threshold = 0.8;
                        }

                        Interfaces.GenericTools.Minimize(Interfaces.GenericTools.MainWindow);
                        System.Threading.Thread.Sleep(100);
                        var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                        if (matches.Count() == 0)
                        {
                            Interfaces.GenericTools.Restore();
                            return(Rectangle.Empty);
                        }
                        match = matches[0];
                    }
                }
            }

            return(match);
        }
        private async void btn_Select(object sender, RoutedEventArgs e)
        {
            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    break;
                }
                if (loadFrom.ItemType == typeof(GetText))
                {
                    gettext = loadFrom;
                }
                loadFrom = loadFrom.Parent;
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    match = await getrectangle.GetitAsync();

                    tip.Close();
                    tip = null;
                }
            }
            else
            {
                var Image       = loadFrom.GetValue <string>("Image");
                var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
                var b           = new System.Drawing.Bitmap(stream);
                var Threshold   = loadFrom.GetValue <double>("Threshold");
                var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                var Processname = loadFrom.GetValue <string>("Processname");
                var limit       = loadFrom.GetValue <Rectangle>("Limit");
                if (Threshold < 0.5)
                {
                    Threshold = 0.8;
                }

                Interfaces.GenericTools.minimize(Interfaces.GenericTools.mainWindow);
                System.Threading.Thread.Sleep(100);
                var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                if (matches.Count() == 0)
                {
                    Interfaces.GenericTools.restore();
                    return;
                }
                match = matches[0];
            }

            Rectangle rect = Rectangle.Empty;

            using (Interfaces.Overlay.OverlayWindow _overlayWindow = new Interfaces.Overlay.OverlayWindow(true))
            {
                _overlayWindow.BackColor = System.Drawing.Color.Blue;
                _overlayWindow.Visible   = true;
                _overlayWindow.Bounds    = match;
                _overlayWindow.TopMost   = true;

                var tip = new Interfaces.Overlay.TooltipWindow("Select relative area to capture");
                rect = await getrectangle.GetitAsync();

                tip.Close();
                tip = null;
            }

            ModelItem.Properties["OffsetX"].SetValue(new System.Activities.InArgument <int>(rect.X - match.X));
            ModelItem.Properties["OffsetY"].SetValue(new System.Activities.InArgument <int>(rect.Y - match.Y));
            ModelItem.Properties["Width"].SetValue(new System.Activities.InArgument <int>(rect.Width));
            ModelItem.Properties["Height"].SetValue(new System.Activities.InArgument <int>(rect.Height));
            Interfaces.GenericTools.restore();
        }
        private void Highlight_Click(object sender, RoutedEventArgs e)
        {
            var OffsetX = ModelItem.GetValue <int>("OffsetX");
            var OffsetY = ModelItem.GetValue <int>("OffsetY");
            var Width   = ModelItem.GetValue <int>("Width");
            var Height  = ModelItem.GetValue <int>("Height");

            ModelItem loadFrom = ModelItem.Parent;
            string    loadFromSelectorString = "";
            ModelItem gettext = null;

            while (loadFrom.Parent != null)
            {
                var p = loadFrom.Properties.Where(x => x.Name == "Image").FirstOrDefault();
                if (p != null)
                {
                    loadFromSelectorString = loadFrom.GetValue <string>("Selector");
                    break;
                }
                if (loadFrom.ItemType == typeof(GetText))
                {
                    gettext = loadFrom;
                }
                loadFrom = loadFrom.Parent;
            }
            Interfaces.IElement element = null;
            Rectangle           match   = Rectangle.Empty;

            if (!string.IsNullOrEmpty(loadFromSelectorString))
            {
                var selector   = new Interfaces.Selector.Selector(loadFromSelectorString);
                var pluginname = selector.First().Selector;
                var Plugin     = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var elements   = Plugin.GetElementsWithSelector(selector, null, 1);
                if (elements.Length > 0)
                {
                    element = elements[0];
                }
            }
            if (gettext != null && element != null)
            {
                var matches = GetText.Execute(element, gettext);
                if (matches.Length > 0)
                {
                    match = matches[0].Rectangle;
                }
                else
                {
                    return;
                    //var tip = new Interfaces.Overlay.TooltipWindow("Mark a found item");
                    //match = await getrectangle.GetitAsync();
                    //tip.Close();
                    //tip = null;
                }
            }
            else
            {
                var Image       = loadFrom.GetValue <string>("Image");
                var stream      = new System.IO.MemoryStream(Convert.FromBase64String(Image));
                var b           = new System.Drawing.Bitmap(stream);
                var Threshold   = loadFrom.GetValue <double>("Threshold");
                var CompareGray = loadFrom.GetValue <bool>("CompareGray");
                var Processname = loadFrom.GetValue <string>("Processname");
                var limit       = loadFrom.GetValue <Rectangle>("Limit");
                if (Threshold < 0.5)
                {
                    Threshold = 0.8;
                }

                // Interfaces.GenericTools.minimize(Interfaces.GenericTools.mainWindow);
                System.Threading.Thread.Sleep(100);
                var matches = ImageEvent.waitFor(b, Threshold, Processname, TimeSpan.FromMilliseconds(100), CompareGray, limit);
                if (matches.Count() == 0)
                {
                    Interfaces.GenericTools.restore();
                    return;
                }
                match = matches[0];
            }

            var _hi = new ImageElement(match);

            _hi.Highlight(false, System.Drawing.Color.Blue, TimeSpan.FromSeconds(1));

            var rect = new ImageElement(new Rectangle(_hi.X + OffsetX, _hi.Y + OffsetY, Width, Height));

            rect.Highlight(false, System.Drawing.Color.PaleGreen, TimeSpan.FromSeconds(1));
        }