public static string GetTextFromImage(string path)
        {
            Bitmap         bitmap    = new Bitmap(path);
            GoogleCloudApi googleApi = new GoogleCloudApi();
            string         output    = googleApi.RecognizeText(bitmap, new List <string>()
            {
                "pl", "en"
            }, 10000);

            return(output);
        }
Beispiel #2
0
        public void Execute(Arguments arguments)
        {
            var screenArea  = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates();
            var screenImage = RobotWin32.GetPartOfScreen(screenArea);
            var timeout     = (int)arguments.Timeout.Value.TotalMilliseconds;
            var languages   = arguments.Languages.Value.Split(',').ToList();
            var googleApi   = new GoogleCloudApi();
            var text        = googleApi.RecognizeText(screenImage, languages, timeout);

            if (string.IsNullOrEmpty(text))
            {
                throw new NullReferenceException("Ocr was unable to find text");
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, new TextStructure(text));
        }
Beispiel #3
0
        public void Execute(Arguments arguments)
        {
            Rectangle      rectangle    = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates();
            Bitmap         partOfScreen = RobotWin32.GetPartOfScreen(rectangle);
            int            timeout      = (int)arguments.Timeout.Value.TotalMilliseconds;
            List <string>  languages    = arguments.Languages.Value.Split(',').ToList();
            string         search       = arguments.Search.Value;
            GoogleCloudApi googleApi    = new GoogleCloudApi();
            Rectangle      output       = googleApi.RecognizeText(partOfScreen, search, languages, timeout);

            if (Equals(output, new Rectangle(-1, -1, -1, -1)))
            {
                throw new NullReferenceException("Ocr was unable to find text");
            }
            Scripter.Variables.SetVariableValue(arguments.Result.Value, new RectangleStructure(output));
        }
        public void Execute(Arguments arguments)
        {
            var screenArea  = !arguments.Relative.Value ? arguments.Area.Value : arguments.Area.Value.ToAbsoluteCoordinates();
            var screenImage = RobotWin32.GetPartOfScreen(screenArea);
            var timeout     = (int)arguments.Timeout.Value.TotalMilliseconds;
            var languages   = arguments.Languages.Value.Split(',').ToList();
            var search      = arguments.Search.Value;
            var googleApi   = new GoogleCloudApi();
            var rectangle   = googleApi.FindTextPosition(screenImage, search, languages, timeout);

            if (rectangle == null)
            {
                throw new NullReferenceException("Ocr was unable to find text position");
            }

            Scripter.Variables.SetVariableValue(arguments.Result.Value, new RectangleStructure(rectangle.Value));
        }
Beispiel #5
0
        public void Execute(Arguments arguments)
        {
            if (!string.IsNullOrEmpty(arguments.ApiKey?.Value))
            {
                GoogleCloudApi.InitializeApiKeyCredential(arguments.ApplicationName.Value, arguments.ApiKey.Value);
            }
            else if (!string.IsNullOrEmpty(arguments.JsonCredential?.Value))
            {
                GoogleCloudApi.InitializeJsonCredential(arguments.ApplicationName.Value, arguments.JsonCredential.Value);
            }
            else
            {
                throw new ArgumentException($"You must provide {nameof(arguments.ApiKey)} or {nameof(arguments.JsonCredential)} argument to log in to the Google Cloud Service");
            }

            OnScriptEnd = () => GoogleCloudApi.ClearCredential();
        }