【问题标题】:Not Able To Use PixConverter.ToPix Leptonica C#无法使用 PixConverter.ToPix Leptonica C#
【发布时间】:2018-05-24 00:38:41
【问题描述】:

我想将位图转换为 Leptonica.Pix.. 所以在我进行搜索后,我发现有人在这里遇到了同样的问题: Tesseract .NET Process image from memory object

所以解决这个问题的方法是使用 PixConverter.ToPix() 方法。

我的问题是我在最新安装的 Leptonica 包中找不到这个方法。我试图删除并重新安装最新版本的 Nuget,但该方法仍然不存在。

我应该怎么做才能使用 PixConverter.ToPix()?。提前致谢。

编辑:我忘了提到我也在使用最新的 Tessercat pacakge。

【问题讨论】:

  • 只是好奇,这是 .net 框架、核心还是标准?

标签: c# ocr tesseract leptonica


【解决方案1】:

您需要使用版本“3.0.2”才能使此 (PixConverter.ToPix()) 工作。

所以你的 .csproj 文件应该在 version 中有这个 exact 匹配:

<PackageReference Include="Tesseract" Version="3.0.2" />

希望对你有帮助。

【讨论】:

  • 我正在使用 3.3.0,但问题仍然存在。
  • @PratapSinghMehra 你试过 3.0.2 版吗?
  • 没有。所以我使用了 Pix.LoadTiffFromMemory(fileBytes)) 方法
【解决方案2】:

在 Tesseract 4 中,有一种新方法可以使用以下语法进行转换:

var pixFromByteArray = Pix.LoadFromMemory(byteArray);
var pixFromFile = Pix.LoadFromFile(fileName);

【讨论】:

    【解决方案3】:

    它位于Tesseract命名空间中,更多信息可以在这里找到https://github.com/charlesw/tesseract

    namespace Tesseract
    {
        /// <summary>
        /// Handles converting between different image formats supported by DotNet.
        /// </summary>
        public static class PixConverter
        {
            private static readonly BitmapToPixConverter bitmapConverter = new BitmapToPixConverter();
            private static readonly PixToBitmapConverter pixConverter = new PixToBitmapConverter();
    
            /// <summary>
            /// Converts the specified <paramref name="pix"/> to a Bitmap.
            /// </summary>
            /// <param name="pix">The source image to be converted.</param>
            /// <returns>The converted pix as a <see cref="Bitmap"/>.</returns>
            public static Bitmap ToBitmap(Pix pix)
            {
                return pixConverter.Convert(pix);
            }
    
            /// <summary>
            /// Converts the specified <paramref name="img"/> to a Pix.
            /// </summary>
            /// <param name="img">The source image to be converted.</param>
            /// <returns>The converted bitmap image as a <see cref="Pix"/>.</returns>
            public static Pix ToPix(Bitmap img)
            {
                return bitmapConverter.Convert(img);
            }
        }
    }
    

    根据网站登陆page

    通过从包管理器控制台运行 Install-Package Tesseract 添加 Tesseract NuGet 包。

    此外,它值得彻底阅读该网站。

    免责声明,我之前没用过这个库,只是查了一下资料

    更新

    为了确保我没有给你坏信息,我创建了一个新项目,下载了最新的 Tesseract nuget。并且能够做到以下几点。

    using Tesseract;
    
    ...
    
    PixConverter.ToPix()
    

    更新2

    您注意到的问题是因为您正在使用

    https://www.nuget.org/packages/tesseract.net/

    相对于

    https://www.nuget.org/packages/Tesseract/

    现在我不确定你真正想要什么。但是前者不存在该方法

    【讨论】:

    • 我也在使用最新的 Tessercat 包,仍然无法使用该方法。
    • 好吧,原来这个方法存在于3.0.2版本..你在用这个版本吗>@TheGeneral
    • @Mick2160 是的,我所做的测试是最新的 3.0.2
    • 那么问题是这个方法在v4+版本中不存在。
    • @Mick2160 我没有看到任何 v4 版本,但我很高兴你已经弄清楚了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 2012-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多