private async Task MessageReceivedAsync (IDialogContext context, IAwaitable <IMessageActivity> result) { var messageResult = await result; var cvs = new OCRService(); var finalResult = string.Empty; // 上傳圖片的處理 if (messageResult.Attachments?.Any(a => a.ContentType.Contains("image")) ?? false) { var attachment = messageResult.Attachments.FirstOrDefault(x => x.ContentType.Contains("image")); var imageStream = await messageResult.GetConnector().GetImageStream(attachment); var ocrResult = await cvs.GetOcrResultAsync(imageStream, "zh-Hant"); finalResult = ProcessImageOcrResult(context, ocrResult); } // 圖片網址的處理 else if (Uri.IsWellFormedUriString(messageResult.Text, UriKind.Absolute)) { var ocrResult = await cvs.GetOcrResultAsync(messageResult.Text, "zh-Hant"); finalResult = ProcessImageOcrResult(context, ocrResult); } context.Done(finalResult); }
public MainViewModel() { _machineContext = new MachineContext(); ClickCommand = new ParameterCommand <string>(OnClick); SelectItemCommand = new ParameterCommand <string>(OnItemSelected); MenuCommand = new ParameterCommand <string>(OnMenuItemSelected); OnDropCommand = new ParameterCommand <DragEventArgs>(OnDrop); _imageService = new ImageService(); _OCRService = new OCRService(); _windowsManager = new WindowsManager(); WindowHeight = SystemParameters.PrimaryScreenHeight * 0.6; WindowWidth = SystemParameters.PrimaryScreenWidth * 0.6; SelectedOCRLanguage = "eng"; WindowVisibility = Visibility.Visible; OCRResult = new List <string>(); }
public Servicos() { WebService = new WebService( new WebDriverContextInfo() { Path = System.String.Concat(System.Environment.CurrentDirectory, @"\Drivers"), MaximizeWindow = false, Browser = BrowserEnum.InternetExplorer, Driver = DriverEnum.Selenium, Timeout = 60, Attempts = 10, MaxAttempts = 10 } ); DesktopService = new DesktopService( new DesktopDriverContextInfo() { Driver = DriverEnum.TestStack, Timeout = 30, Attempts = 10, MaxAttempts = 10 //,Path= System.String.Concat(System.Environment.CurrentDirectory, @"\Drivers") } ); OCRService = new OCRService( new OCRDriverContextInfo() { Driver = DriverEnum.Sikuli, Matching = 0.9, Timeout = 60, Attempts = 10, MaxAttempts = 10 } ); }
public OCRController(OCRService ocrService) { this.ocrService = ocrService; }
public OCRController(OCRService ocrService) { _ocrService = ocrService; }
private void ProcessScreenshot(string filePath) { bool writeOutStats = false; imageProcessingStopWatch = new Stopwatch(); imageProcessingStopWatch.Start(); string imageText = OCRService.GetImageWords(filePath); imageProcessingStopWatch.Stop(); totalScreenProcessed++; SetTotalImagesScannedLabel(totalScreenProcessed.ToString()); totalProcessingTime += imageProcessingStopWatch.Elapsed.TotalSeconds; SetAverageProcessingTimeLabel((totalProcessingTime / totalScreenProcessed).ToString()); /* * Some hacky ass processing right here, but whatever gets the job done, ya know/ */ List <string> textParts = imageText .Split(' ') .Select(z => z.ToLower().Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ")) .SelectMany(z => z.Split(' ')) .ToList(); if (textParts.Contains("kills") || textParts.Contains("kill") || textParts.Contains("ikill") || textParts.Count > 2 && textParts[0] == "you" && textParts[1] == "killed" || textParts.Any(z => z.IndexOf("m)") > -1) ) { try { if (DateTime.UtcNow.AddSeconds(-6) > PUBGStats.LastKill) { PUBGStats.Kills++; PUBGStats.LastKill = DateTime.UtcNow; SetKillsLabel(PUBGStats.Kills.ToString()); writeOutStats = true; } } catch (Exception ex) { //Meh } } //else if (textParts.Contains("next") || textParts.Any(z => z.IndexOf("time!") > -1)) else if (textParts.Contains("killed")) { try { int killedIndex = textParts.IndexOf("killed"); if (textParts[killedIndex + 1] == "you" && DateTime.UtcNow.AddMinutes(-2) > PUBGStats.LastDeath) { //This death ocurred more than 2 minutes after the last, probs real PUBGStats.Deaths++; PUBGStats.LastDeath = DateTime.UtcNow; SetDeathsLabel(PUBGStats.Deaths.ToString()); writeOutStats = true; } } catch (Exception ex) { } } //else if (textParts.Contains("winner")) //{ // try // { // if (DateTime.UtcNow.AddMinutes(-20) > PUBGStats.LastWin) // { // //This win happened 20 mins after the last, probs real // PUBGStats.Wins++; // PUBGStats.LastWin = DateTime.UtcNow; // writeOutStats = true; // } // } // catch (Exception ex) // { // } //} if (writeOutStats) { try { WriteStats(); } catch (Exception) { } } /* * Wipe the screenshot directory every 10 */ if (this.cbDeleteImagesAfterProcessing.Checked && totalScreenProcessed % 10 == 0) { DirectoryInfo di = new DirectoryInfo(applicationSettings.ScreenshotDirectory); Parallel.ForEach(di.GetFiles(), file => { file.Delete(); }); } }
public UploadController(ElasticsearchService elasticsearchService, OCRService ocrService) { _elasticsearchService = elasticsearchService; _ocrService = ocrService; }