Search code examples
c#ocrtesseractleptonica

Not Able To Use PixConverter.ToPix Leptonica C#


I wanted to convert a bitmap to Leptonica.Pix.. So after I did a search I found someone who had the same problem here: Tesseract .NET Process image from memory object

So the solution to this problem was to use PixConverter.ToPix() method.

My problem here is that I can't find this method in the latest installed Leptonica Package. I tried to remove the and reinstall the lateset version thought Nuget but the method is still not not there.

What should I do to be able to use PixConverter.ToPix()?. Thanks in advance.

EDIT: I forgot to mention that i'm using the latest Tessercat pacakge too.


Solution

  • It lives in Tesseract namespace, more information can be found here 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);
            }
        }
    }
    

    As per the sites landing page

    Add the Tesseract NuGet Package by running Install-Package Tesseract from the Package Manager Console.

    Also, its worth while reading the site thoroughly.

    Disclaimer, i have never used this library before, just looked up the information

    Update

    Just to make sure i wasn't giving you bad information, I created a new project, downloaded the latest Tesseract nuget. And was able to do the following.

    using Tesseract;
    
    ...
    
    PixConverter.ToPix()
    

    Update2

    The problem you are noticing is because you are using

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

    apposed to

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

    Now 'im not sure what one you actually want. However that method dosnt not exist in the former