Exemple #1
0
        public async Task AnalyseAsync()
        {
            var bitmap   = Screenshot.ActiveWindow();
            var fileName = $"{DateTime.Now.ToString("yyyy_MM_dd_hh_mm_")}{Guid.NewGuid().ToString()}.png";

            bitmap.Save(fileName, ImageFormat.Png);
            await ComputerVision.ReadBitmapAsync(fileName, CancellationToken.None);
        }
        public async void ImagemCapturada(byte[] bytes)
        {
            // comprime
            var comprimido = Compress(bytes);

            // envia api
            string descricao = await ComputerVision.DescreverImagem(bytes);

            // traduz

            // fala
        }
Exemple #3
0
        /// <summary>
        /// Constructs a new eyes object.
        /// </summary>
        /// <param name="visionPreview">A capture element that is placed on a canvas used for capturing what Robbie sees.</param>
        /// <param name="previewCanvas">A canvas element used for rendering the image preview showing what Robbie sees.</param>
        public Eyes(CaptureElement visionPreview, Canvas previewCanvas)
        {
            Camera.Instance.Initialize(visionPreview);
            this.previewCanvas = previewCanvas;

            faceTracking   = new FaceTracking();
            faceDetection  = new FaceDetection();
            computerVision = new ComputerVision();

            identityInterpolation = new IdentityInterpolation();
            visualization         = new Vision();
            panTilt     = new PanTilt();
            eyesDisplay = new EyesDisplay();

            identityInterpolation.LargestFaceChanged += IdentityInterpolation_LargestFaceChanged;

            // fire up the continuous tasks of processing video and controlling the servos
            ThreadPoolTimer.CreatePeriodicTimer(ProcessCurrentVideoFrame_Delegate, TimeSpan.FromMilliseconds(125)); // 8 fps
            ThreadPoolTimer.CreatePeriodicTimer(UpdatePanTiltPosition_Delegate, TimeSpan.FromMilliseconds(25));     // 40 fps
            ThreadPoolTimer.CreatePeriodicTimer(Blink_Delegate, TimeSpan.FromMilliseconds(5000));                   // 12 fpm
        }
        internal async Task ReadImageOcrTextAndTranslate(string toLanguage = "en-US")
        {
            string inputImageFilePath = Path.Combine(
                HelperFunctions.GetSampleDataFullPath(customSettings.SampleDataFolders.PhotosToAnalyzeFolder),
                customSettings.SampleIndividualFiles.PhotoFileToProcess
                );

            string fileNamePrefix  = Path.GetFileName(inputImageFilePath);
            string outFolder       = HelperFunctions.GetSampleDataFullPath(customSettings.SampleDataFolders.AnalyzedImagesFolder);
            string outBaseFilePath = Path.Combine(outFolder, fileNamePrefix);

            // ensure destination Path exists
            Directory.CreateDirectory(outFolder);



            // OCR - text extraction

            // Get vision client

            Console.WriteLine($"Extracting Text using Vision OCR from {inputImageFilePath}...");

            ComputerVisionClient visionClient = ComputerVision.Authenticate(
                customSettings.ComputerVisionSettings.Endpoint,
                customSettings.ComputerVisionSettings.Key);

            string ocrFilePath = outBaseFilePath + "-ReadOcrResults.txt";

            var ocrResult = await ComputerVision.RecognizeTextFromImageLocal(visionClient, inputImageFilePath, false);

            var ocrLineTexts = ComputerVisionHelper.GetOcrResultLineTexts(ocrResult);
            await File.WriteAllLinesAsync(ocrFilePath, ocrLineTexts);

            Console.WriteLine($"Generated OCR output file {ocrFilePath}.");
            Console.WriteLine();

            // Detect Languages using Text Analytics Api
            TextAnalyticsClient textClient = TextAnalytics.GetClient(
                customSettings.TextAnalyticsSettings.Key,
                customSettings.TextAnalyticsSettings.Endpoint
                );


            Console.WriteLine("Detect the language from generated OCR text using TextAnalytics...");
            IEnumerable <string> sourceLanguages = await TextAnalytics.DetectLanguageBatchAsync(textClient, ocrLineTexts);

            //Console.WriteLine($"Detected languages Count: {sourceLanguages.Count()}");
            //Console.WriteLine($"Detected Languages: {string.Join(", ", sourceLanguages)}");
            Console.WriteLine();


            // Now translate the extracted text (OCR) to output language (here default is English)
            Console.WriteLine($"Now translate the generated OCR file to English {toLanguage}...");

            string ocrText = await File.ReadAllTextAsync(ocrFilePath);

            string translatedText = await JournalHelper.Translator.Translate.TranslateTextRequestAsync(
                customSettings.TranslatorConfigSettings.Key,
                customSettings.TranslatorConfigSettings.Endpoint,
                toLanguage,
                ocrText
                );

            string outTranslatedFilePath = outBaseFilePath + "-translated-" + toLanguage + ".json";

            if (!translatedText.StartsWith("["))
            {
                Console.WriteLine($"Storing the generated translation output to file: {outTranslatedFilePath}... ");
                var json = JObject.Parse(translatedText);
                Helper.WriteToJsonFile <JObject>(outTranslatedFilePath, json);

                if (json.ContainsKey("error"))
                {
                    Console.WriteLine($"\t\t\tTRANSLATOR ERROR: {json["error"]["code"]}");
                    Console.WriteLine($"\t\t\tMESSAGE: {json["error"]["message"]}");
                    return;
                }
            }

            string txtFile = outTranslatedFilePath + ".txt";

            Console.WriteLine($"Generating txt file with translated texts - {txtFile}");

            IEnumerable <string> texts = JournalHelper.Translator.Translate.GetTranslatedTexts(translatedText);
            await File.WriteAllLinesAsync(txtFile, texts);

            Console.WriteLine();
        }
Exemple #5
0
 public App()
 {
     // The root page of your application
     MainPage = new CameraPage();
     ComputerVision.MakeRequest();
 }
Exemple #6
0
        public override async void OnButtonClick(ConsoleButton consoleButton)
        {
            switch (consoleButton.Name)
            {
            case "GetImage":

                var imageUrl = ImageEndpoint.GetPictureUrl();
                var computerVisionResponse = await ComputerVision.ProcessImageAsync(imageUrl);

                using (IRSAPIClient proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
                {
                    //Set the proxy to use the current workspace
                    proxy.APIOptions.WorkspaceID = Helper.GetActiveCaseID();
                    var imageArtifactId = ActiveArtifact.ArtifactID;

                    var rdoToUpdate = proxy.Repositories.RDO.ReadSingle(imageArtifactId);

                    rdoToUpdate.ArtifactTypeGuids.Add(Helpers.Constants.IMAGE_OBJECT_GUID);
                    rdoToUpdate.Fields.Add(new DTOs.FieldValue(Helpers.Constants.IMAGE_URL_FIELD_GUID, imageUrl));
                    rdoToUpdate.Fields.Add(new DTOs.FieldValue(Helpers.Constants.IMAGE_DESCRIPTION_FIELD_GUID, computerVisionResponse.Description));
                    rdoToUpdate.Fields.Add(new DTOs.FieldValue(Helpers.Constants.IMAGE_STATUS_FIELD_GUID, computerVisionResponse.ShibaStatus));

                    proxy.Repositories.RDO.Update(rdoToUpdate);
                }
                break;

            case "Correct":

                using (IRSAPIClient proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
                {
                    //Set the proxy to use the current workspace
                    proxy.APIOptions.WorkspaceID = Helper.GetActiveCaseID();
                    var imageArtifactId = ActiveArtifact.ArtifactID;

                    var rdoToUpdate = proxy.Repositories.RDO.ReadSingle(imageArtifactId);

                    rdoToUpdate.ArtifactTypeGuids.Add(Helpers.Constants.IMAGE_OBJECT_GUID);
                    rdoToUpdate.Fields.Add(new DTOs.FieldValue(Helpers.Constants.IMAGE_RESULT_FIELD_GUID, "Correct"));

                    proxy.Repositories.RDO.Update(rdoToUpdate);
                }
                break;

            case "FalseNegative":

                using (IRSAPIClient proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
                {
                    //Set the proxy to use the current workspace
                    proxy.APIOptions.WorkspaceID = Helper.GetActiveCaseID();
                    var imageArtifactId = ActiveArtifact.ArtifactID;

                    var rdoToUpdate = proxy.Repositories.RDO.ReadSingle(imageArtifactId);

                    rdoToUpdate.ArtifactTypeGuids.Add(Helpers.Constants.IMAGE_OBJECT_GUID);
                    rdoToUpdate.Fields.Add(new DTOs.FieldValue(Helpers.Constants.IMAGE_RESULT_FIELD_GUID, "False Negative"));

                    proxy.Repositories.RDO.Update(rdoToUpdate);
                }
                break;

            case "FalsePositive":

                using (IRSAPIClient proxy = Helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System))
                {
                    //Set the proxy to use the current workspace
                    proxy.APIOptions.WorkspaceID = Helper.GetActiveCaseID();
                    var imageArtifactId = ActiveArtifact.ArtifactID;

                    var rdoToUpdate = proxy.Repositories.RDO.ReadSingle(imageArtifactId);

                    rdoToUpdate.ArtifactTypeGuids.Add(Helpers.Constants.IMAGE_OBJECT_GUID);
                    rdoToUpdate.Fields.Add(new DTOs.FieldValue(Helpers.Constants.IMAGE_RESULT_FIELD_GUID, "False Positive"));

                    proxy.Repositories.RDO.Update(rdoToUpdate);
                }
                break;
            }
        }