views:

602

answers:

2

Hi, I decided to use tessnet2 library for my windows mobile project. Unfortunetly while I am trying to compile it, it throws an error:

  1. The best overloaded method match for 'tessnet2.Tesseract.GetThresholdedImage(System.Drawing.Bitmap, System.Drawing.Rectangle)' has some invalid arguments

  2. The type 'System.Drawing.Rectangle' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

  3. The type 'System.Drawing.Bitmap' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

  4. Argument '1': cannot convert from 'System.Drawing.Bitmap [c:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\System.Drawing.dll]' to 'System.Drawing.Bitmap []'

  5. Argument '2': cannot convert from 'System.Drawing.Rectangle [c:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE\System.Drawing.dll]' to 'System.Drawing.Rectangle []'

  6. The best overloaded method match for 'tessnet2.Tesseract.DoOCR(System.Drawing.Bitmap, System.Drawing.Rectangle)' has some invalid arguments

ok, I know. Add reference to the assembly. The problem is, that I did it. I add reference by 'Add Reference' in Solution Explorer (System.Drawing), and I even have it declared as 'using System.Drawing'. Intellisense works without any problem. When i write 'rect' it automaticlly shows me the list with 'Rectangle' structure on top.

What is the problem? The assembly is added, even intellisense sees it, why compilator doesn't? :/

here is the code:

using System;

using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms;

namespace MPT2 { public partial class Form1 : Form { Ocr ocr;

    public Form1()
    {
        InitializeComponent();
        DoIT();
    }

    public void DoIT()
    {
        ocr = new Ocr();
        using (Bitmap bmp = new Bitmap("no_smoking.jpg"))
        {
            tessnet2.Tesseract tessocr = new tessnet2.Tesseract();
            tessocr.Init(null, "eng", false);

            tessocr.GetThresholdedImage(bmp, Rectangle.Empty).Save("elo.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);

            Console.WriteLine("dsadasdasd");
            ocr.DoOCRNormal(bmp, "eng");

        }
    }

}

public class Ocr
{
    public void DumpResult(List<tessnet2.Word> result)
    {
        foreach (tessnet2.Word word in result)
        {
            Console.WriteLine("{0} {1}", word.Confidence, word.Text);
        }
    }

    public List<tessnet2.Word> DoOCRNormal(Bitmap image, string lang)
    {
        tessnet2.Tesseract ocr = new tessnet2.Tesseract();
        ocr.Init(null, lang, false);

        List<tessnet2.Word> result = ocr.DoOCR(image, Rectangle.Empty);
        DumpResult(result);
        return result;
    }
}

}

It actually the same as on this site .

help please ;/

PS. I am using Windows Mobile SDK 6 standart

.

A: 

The compact framework and standard framework are 2 different code bases that exposes a similar API. That is why intellisense 'worked' but the compiler 'complained'.

Your 3rd party OCR framework needs to reference the CompactFramework. Download the source for Tessnet2. Replace the referenced framework assemblies with compact framework assemblies. You'll have to browse for them and find them in "C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE".

jyoung
All references in the Solution Explorer are from C:\Program Files\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE". Error is still showing up.
patric789
I did not look at the site before I answered. Like ctacke said it is managed C++ so you have to pinvoke it. However I see the author also said that the unmanaged code leaked memory. This does not sound like a good code for a mobil app.
jyoung
A: 

Just looking at it, there's no way this is going to work in the Compact Framework. First off the site explicitly says

Tessnet2.dll needs Visual C++ 2008 Runtime

Well, that means it was built for the desktop. It's not going to work on a WinMo device for many reasons, but suffice it to say that you would have to recompile it for the right processor and using the right runtimes. If it uses anything like inline assembler this is going to make porting it really, really challenging.

If you get the tessract library built, you still can't use the tessnet2 managed library.

It's a Visual Studio 2008 C++/CLI project

This means it's a managed C++ project. Managed C++ is not supported by the COmpact Framework. So you'd have to port that to C# or write a separate P/Invoke wrapper that calls the tessract library functions.

ctacke