【问题标题】:How to detect numbers/digits via builtin OcrEngine class如何通过内置 OcrEngine 类检测数字/数字
【发布时间】:2016-09-11 14:24:51
【问题描述】:

我在使用来自 C++/CX 的 Windows UWP OCR-Engine 检测图像中的数字/数字时遇到问题。 我需要检测下图中的数字

我尝试使用 Windows 10 UWP 的内置方法:OcrEngine,代码如下:

...
cv::Mat croppedImage = imread("digit.png");
WriteableBitmap^ bit1 = ref new WriteableBitmap(croppedImage.cols, croppedImage.rows);
SoftwareBitmap^ bit2 = bit2->CreateCopyFromBuffer(bit1->PixelBuffer, BitmapPixelFormat::Bgra8, bit1->PixelWidth, bit1->PixelHeight);
Windows::Globalization::Language^ l = ref new Windows::Globalization::Language("de");
OcrEngine^ ocrEngine = OcrEngine::TryCreateFromLanguage(l);
IAsyncOperation<OcrResult^>^ ao = ocrEngine->RecognizeAsync(bit2);
task_completion_event<Platform::String^> purchaseCompleted;
auto deviceEnumTask = create_task(ao);
deviceEnumTask.then([this](OcrResult^ result)
{
App1::MainPage::findNumber(result->Text);
});
...
void App1::MainPage::findNumber(Platform::String^ text)
{
//Do something with String
}

我现在的问题是,findNumber 中插入的字符串始终为空。我尝试使用不同的图片作为输入,但结果始终相同:NULL。

  1. 有没有更简单的方法在 C++/CX 中获取此图像中的数字?
  2. 可能是什么问题?转换图像?

【问题讨论】:

  • 官方有OCR sample in GitHub,可以查一下。但是,当我用它来识别你的图像时,它也无法识别它。 OcrEngine 不保证它可以正确识别图像。文本识别的准确性取决于图像的质量。欲了解更多信息,请参阅Windows.Media.Ocr namespace
  • 感谢您的回答。与此同时,我发现了我的错误。问题是将 SoftwareBitmap 转换为 WriteableBitmap。我稍后会发布解决方案。我也无法在我的图像中使用 OCR 识别单个数字。我将文本从“2”更改为“Raum 2”,一切正常。

标签: windows multithreading win-universal-app ocr c++-cx


【解决方案1】:

问题在于将 WriteableBitmap 转换为 SoftwareBitmap WriteableBitmap^ bit1 = ref new WriteableBitmap(croppedImage.cols,croppedImage.rows); // 访问像素 IBuffer^ 缓冲区 = bit1->PixelBuffer; 无符号字符* dstPixels;

        // Obtain IBufferByteAccess
        ComPtr<IBufferByteAccess> pBufferByteAccess;
        ComPtr<IInspectable> pBuffer((IInspectable*)buffer);
        pBuffer.As(&pBufferByteAccess);

        // Get pointer to pixel bytes
        pBufferByteAccess->Buffer(&dstPixels);
        memcpy(dstPixels, croppedImage.data, croppedImage.step.buf[1] * croppedImage.cols*croppedImage.rows);
        SoftwareBitmap^ bit2= ref new SoftwareBitmap(BitmapPixelFormat::Bgra8, croppedImage.cols, croppedImage.rows);
        //SoftwareBitmap^ bit2 = 
        bit2->CopyFromBuffer(bit1->PixelBuffer);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-06
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-01
    • 2021-12-19
    相关资源
    最近更新 更多