Example #1
0
        internal CvResult DoCVAction(CvActionType actionType,
                                     string templateImagePath,
                                     int matchingThreshold,
                                     int matchingInterval,
                                     int retry,
                                     Rectangle rect,
                                     string sourceImagePath = "")
        {
            if (File.Exists(templateImagePath))
            {
                var psi = new ProcessStartInfo();
                psi.FileName        = _FlaxCV_exe;
                psi.WindowStyle     = ProcessWindowStyle.Normal;
                psi.UseShellExecute = false;
                int minimizeCucumber = 0;
                int width            = rect.Width;
                int height           = rect.Height;
                var psb = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
                if (width <= 0 || height <= 0)
                {
                    // Get full screen capture if capture width <= 0.
                    width  = psb.Width;
                    height = psb.Height;
                }
                if (rect.X >= psb.Width - 300 && rect.Y >= psb.Height - 250)
                {
                    // Minimize Flax.CV.exe if search area might overlaps on it.
                    minimizeCucumber = -1;
                }
                int    a     = (int)actionType;
                string sArgs = string.Format(@"{0} ""{1}"" {2} {3} {4} {5} {6} {7} {8} {9} ""{10}""",
                                             (int)actionType,      // Command
                                             templateImagePath,    // Template image path
                                             matchingThreshold,    // Matching threshold
                                             matchingInterval,     // Matching interval
                                             retry,                // Number of retry
                                             minimizeCucumber,
                                             rect.X,               // Capture start point x
                                             rect.Y,               // Capture start point y
                                             width,                // Capture width
                                             height,               // Capture height
                                             sourceImagePath);     // Compared image path
                psi.Arguments = sArgs;
                var p = Process.Start(psi);

                int matchedLevel = 0;
                int posX = -1, posY = -1;
                if (_waitExit)
                {
                    p.WaitForExit();
                    int exitCode = p.ExitCode;
                    if (exitCode >= 0)
                    {
                        // Get 25 to 31bit value
                        matchedLevel = exitCode >> 24;
                        // Get 13 to 24bit value + offset x = detected x cordinate
                        posX = ((exitCode >> 12) & 0xFFF) + rect.X;
                        // Get 1 to 12bit value + offset y = detected y cordinate
                        posY = (exitCode & 0xFFF) + rect.Y;
                    }
                    else
                    {
                        string cuexeName = Path.GetFileNameWithoutExtension(_FlaxCV_exe);
                        if (exitCode == -4)
                        {
                            //SysLog.MyWarning(string.Format("{0} : Timeout", cuexeName));
                        }
                    }
                }
                //SysLog.DebugPrint(String.Format("Matched={0} at ({1},{2})", iMatched.ToString(), iPosX.ToString(), iPosY.ToString()));
                p.Close();
                p.Dispose();
                bool isMatched = matchedLevel >= _matchingThreshold;
                return(new CvResult(matchedLevel, posX, posY, isMatched));
            }
            //SysLog.MyError("IfFileExistsThenDoAction", "Template file does not exist. " + templateFileFullPath);
            return(new CvResult());
        }
Example #2
0
 internal CvResult ActionOnImage(CvActionType actionType, string templateImagePath, int retryTimes, Rectangle rect, string sourceImagePath = "")
 {
     retryTimes = retryTimes < 0 ? _retryTimes : retryTimes;
     return(DoCVAction(actionType, templateImagePath, _matchingThreshold, _matchingInterval, retryTimes, rect, sourceImagePath));
 }