LoveBoot.ImageFinder.FindAllMatches C# (CSharp) Method

FindAllMatches() public method

Draw rectangles on the ResultImage.
public FindAllMatches ( Byte>.Image source, string match = "", bool copy = true, string ignore = "" ) : Rectangle[]>.IDictionary
source Byte>.Image
match string
copy bool
ignore string
return Rectangle[]>.IDictionary
        public IDictionary<object, Rectangle[]> FindAllMatches(Image<Bgr, Byte> source, string match = "", bool copy = true, string ignore = "") // todo: proper order
        {
            var matches = new ConcurrentDictionary<object, Rectangle[]>();

            Image<Bgr, Byte> sourceImage = copy ? source.Copy() : source;

            foreach (KeyValuePair<object, Image<Bgr, Byte>> subImageKeyValuePair in SubImages)
            {
                if (match.Length > 0 && !subImageKeyValuePair.Key.ToString().Contains(match)) continue;
                if (ignore.Length > 0 && subImageKeyValuePair.Key.ToString().Contains(ignore)) continue;

                Rectangle[] subImageMatches = FindMatches(sourceImage, subImageKeyValuePair.Value, copy);
                matches[subImageKeyValuePair.Key] = subImageMatches;
            }

            /*Parallel.ForEach(SubImages, (subImageKeyValuePair) =>
            {
                if (match.Length > 0 && !subImageKeyValuePair.Key.ToString().Contains(match)) return;
                if (ignore.Length > 0 && subImageKeyValuePair.Key.ToString().Contains(ignore)) return;

                Rectangle[] subImageMatches = FindMatches(sourceImage, subImageKeyValuePair.Value, copy);
                matches[subImageKeyValuePair.Key] = subImageMatches;
                //matches.Add(subImageKeyValuePair.Key, subImageMatches);
            });*/

            return matches;
        } 

Usage Example

Exemplo n.º 1
0
        public void PressThread()
        {
            ImageFinder barImageFinder = new ImageFinder(THRESHOLD_BAR);
            InitializeImageFinder(barImageFinder, "Bar_");

            // if the press-key signal is found, presses the keys found by the state thread

            while (_Enabled)
            {
                using (Image<Bgr, byte> bar_image_source = getCroppedBarScreenshot())
                {
                    if (bar_image_source == null) continue;

                    Dictionary<object, Rectangle[]> matches = barImageFinder.FindAllMatches(bar_image_source, "", false);

                    foreach (KeyValuePair<object, Rectangle[]> pairs in matches)
                    {
                        if (pairs.Value.Length <= 0) continue;

                        Signal matchSignal = (Signal) pairs.Key;

                        int barColumn = pairs.Value[0].Left / KEY_COLUMNS_WIDTH;
                        if (barColumn == lastColumnPressed) continue;

                        if (matchSignal == Signal.Bar_Key || matchSignal == Signal.Bar_Key_Fever)
                        {
                            lastColumnPressed = barColumn;
                            PressKeys(barColumn);

#if DEBUG
                            addDebugImage(bar_image_source, pairs);
#endif

                            System.Threading.Thread.Sleep(50);

                            break;
                        }
                        else // todo: check bar_space explicitly
                        {
                            if (
                                !(gameState[barColumn].Contains(Signal.Key_Space) ||
                                  gameState[barColumn].Contains(Signal.Key_Space_Fever))) continue; // don't press space if there is no space to be pressed, attempt to ignore false positive

                            lastColumnPressed = barColumn;
                            if(matchSignal == Signal.Bar_Space_Alt) System.Threading.Thread.Sleep((pairs.Value[0].Top * 3) / 2); // inaccurate
                            windowFinder.SendKeystroke((ushort)VirtualKeyCode.SPACE);

#if DEBUG
                            addDebugImage(bar_image_source, pairs);
#endif

                            System.Threading.Thread.Sleep(100);
                            break;
                        }
                    }
                }
            }
        }
All Usage Examples Of LoveBoot.ImageFinder::FindAllMatches