Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在解码器操作之前调整位图图像的大小_C#_Xaml_Ocr - Fatal编程技术网

C# 在解码器操作之前调整位图图像的大小

C# 在解码器操作之前调整位图图像的大小,c#,xaml,ocr,C#,Xaml,Ocr,我正在尝试创建一个小的OCR应用程序,在这里我可以选择单词。我已经使用Microsoft示例实现了这一点: protected async override void OnNavigatedTo(NavigationEventArgs e) { // Load image from install folder. var file = await Package.Current.InstalledLocation.GetFileAsync("photo.png"); us

我正在尝试创建一个小的OCR应用程序,在这里我可以选择单词。我已经使用Microsoft示例实现了这一点:

protected async override void OnNavigatedTo(NavigationEventArgs e)
{
    // Load image from install folder.
    var file = await Package.Current.InstalledLocation.GetFileAsync("photo.png");
    using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
    {
        // Create image decoder.
        var decoder = await BitmapDecoder.CreateAsync(stream);

        // Load bitmap.
        var bitmap = await decoder.GetSoftwareBitmapAsync();

        // Extract text from image.
        OcrResult result = await ocrEngine.RecognizeAsync(bitmap);

        // Display recognized text.
        OcrText.Text = result.Text;
    }
}
但是,我希望加载的图像适合屏幕,我只需创建一个BitmapImage,将其源设置为流,并将图像元素的源应用于位图即可。这个问题是OCR单词的坐标与图像不对齐,因为我假设从解码器创建的位图使用原始图像大小。如何纠正此问题,使OCR引擎使用的图像大小与图像元素相同

获取图像和OCR结果的代码:

// Create a stream from the picked file
IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read);

// Create a bitmap from the stream
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(stream);

this.imgDisplay.Source = bitmap;

// Create the decoder from the stream
var decoder = await BitmapDecoder.CreateAsync(stream);

// Get the SoftwareBitmap representation of the file
SoftwareBitmap sBitmap = await decoder.GetSoftwareBitmapAsync();    

mOcrResult = await mOcrEngine.RecognizeAsync(sBitmap);

您没有提供使加载的图像适合屏幕的代码,这是重新处理问题的关键。它只是将XAML图像控件的源设置为拾取文件的位图。问题是,由于从拾取的文件流创建的图像被调整到屏幕大小,单词的坐标未对齐,因为OCR引擎使用未调整大小的流。我想知道在使用OCR引擎之前,是否有一种方法可以调整流的大小。如果更改代码的顺序,首先获得OCR结果,然后设置在imgDisplay中显示图像,该怎么办?它能正常工作吗?不能。由于图像已调整大小,OCR引擎应该具有相同大小的图像,以便文字在技术上处于相同的位置。