C# .NET - Reading Characters and No of lines in a Tiff image

Asked By Caleb 05 on 16-Feb-09 12:44 AM
Hi Frnd's.... Can anyone say how to read no of lines and no characters in a tiff image ... Tks in adv... G.sam...

c# reading Tiff using libtiff

alice johnson replied to Caleb 05 on 16-Feb-09 12:51 AM
public static ImageArray LoadTiff(String Image_Path)
{
    ImageArray arr = null;
    unsafe
    {
        UInt32 w = 0;
        UInt32 h = 0;
        uint samples = 3;
        uint bits = 8;
        int i, j, ptr, lptr;
        int tif = TIFFOpen(Image_Path, "r");
        if (0 != tif)
        {
            TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, ref w);
            TIFFGetField(tif, TIFFTAG_IMAGELENGTH, ref h);
            TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, ref bits);
            TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, ref samples);
            arr = new ImageArray((int)w, (int)h);
            // make sure we get all of the data.
            if (bits == 16)
            {
                UInt32 size = w;
                ushort* raster = (ushort *)_TIFFmalloc((uint)(size * sizeof(ushort) * samples));
                // read in all of the lines
                for (j = 0; j < h; j++)
                {
                    TIFFReadScanline(tif, (byte *)raster, j, 0);
                    // copy line into data
                    for (i = 0, ptr=0; i < w; i++, ptr+=(int)samples)
                    {
                        if (samples == 3)
                        {
                            arr.Data[i + j * w].SetPixel(raster[i], raster[i + 1], raster[i + 2]);
                        }
                        else
                        {
                            ushort val = raster[i + samples - 1];
                            arr.Data[i + j * w].SetPixel(val,val,val);
                        }
                    }
                }
                _TIFFfree((byte *)raster);
            }
            else
            {
                // anything beside 16 bit
                UInt32 size = h * w;
                byte *raster = _TIFFmalloc( size );
                int val = TIFFReadRGBAImage(tif, w, h, raster, 0);
                // copy image data into a bitmap
                if (val != 0)
                {
                    for (j = 0, ptr = 0, lptr=0; j < h; j++)
                    {
                        for (i = 0; i < w; i++, ptr+=4, ptr++)
                        {
                            arr.Data[ptr].SetPixel((ushort)raster[lptr], (ushort)raster[lptr + 1], (ushort)raster[lptr + 2]);
                        } // for i
                    } // for j
                } // if val
                _TIFFfree(raster);
            }
            TIFFClose(tif);
        } // if tif
    } // unsafe
    return arr;
}

read characters from tiff image

C_A P replied to Caleb 05 on 16-Feb-09 12:53 AM
try to use open source OCR library: http://code.google.com/p/tesseract-ocr/

It is very good at redaction as compared to paid ones that I tried. Here's some code with logic as comments

1    Dim OcrOutput As List(Of tessnet2.Word) = Ocr.doOCR(Image1, Rectangle.Empty)
2 'Read words
3 For Each Word As tessnet2.Word In OcrOutput
4 'Read each character in words - so we can look for pattern
5 For Each WordChar As tessnet2.Character In Word.CharList
6 Next
7
8 'Then run regular expression on the words or character combinations to extract out SSN or anthing
9 'And get x,y,height,width for word/char to create rectangles that will be drawn on the image

10 Next
11
  Hope this helps

Reading Characters and No of lines in a Tiff image

mv ark replied to Caleb 05 on 16-Feb-09 01:06 AM
Try the following free & under development OCR engines -
   1. GOCR - http://jocr.sourceforge.net/developers.html
   2. Tesseract - http://code.google.com/p/tesseract-ocr/

or use commercial OCR Toolkits like -
   1. ABBYY FineReader - http://www.abbyy.com/sdk/
   2. OmniPage - http://www.nuance.com/omnipage/capturesdk/

Source: http://mvark.blogspot.com/2009/02/free-ocr-tools.html
c# reading Tiff using libtiff
Caleb 05 replied to alice johnson on 16-Feb-09 01:23 AM
Tks alice johnson... Im new to C#.net can u plz say me step by step process Tks in adv G.sam...
Tks mv ark
Caleb 05 replied to C_A P on 16-Feb-09 01:40 AM
Im new to C#.net can u plz say me step by step process Tks in adv G.sam...
Tks Alice
Caleb 05 replied to alice johnson on 16-Feb-09 02:22 AM
How to use libtiff in C#.net... Tks in Adv G.sam...
Tks C_A P ...
Caleb 05 replied to C_A P on 16-Feb-09 04:02 AM
end of post
Tks C_A P ...
Caleb 05 replied to C_A P on 16-Feb-09 04:03 AM
But Which dll file i should to import Tks in Adv G.sam
hi, Caleb
alice johnson replied to Caleb 05 on 16-Feb-09 11:11 AM

libtiff is teh dll which will help you solve ur task:

'l send you the link to download this dll, download this dll and browse this the dll from the path where you have downloaded it.

http://www.dlldll.com/libtiff.dll_download.html


cheers

Tks Alice ...
Caleb 05 replied to alice johnson on 16-Feb-09 11:20 PM
Tks ....
Tks Alice
Caleb 05 replied to alice johnson on 17-Feb-09 04:51 AM
I have downloaded but where i have to include that still there is an error that Error 1 :The type or namespace name 'ImageArray' could not be found (are you missing a using directive or an assembly reference?)
reply
alice johnson replied to Caleb 05 on 17-Feb-09 10:38 AM

Did you add the dll to your current project.

If you have included teh dll, this error will be coming.

check if u have added the dll to the project

how to add the file
joe t replied to alice johnson on 11-Apr-09 12:00 PM

i dont think we can add this dll directly, right?


do we need to use a DLLImport[] and if so, do you have the structure for this?


thanks!

Joe

libtiff
joe t replied to alice johnson on 13-Apr-09 05:23 PM

Hi Alice,


i understand your code, but how do i DLLImport the library into c# (libtiff.dll)


thanks,

Joe

structure
joe t replied to joe t on 13-Apr-09 05:54 PM

found your other page and copied the dllimport from that...


thanks

joe

lo malli vacha neenu
alice johnson replied to joe t on 14-Apr-09 03:33 AM
end of post
hey sorry for the worng sub....
alice johnson replied to Caleb 05 on 14-Apr-09 03:34 AM
'l be posting ur reply sooon............
libtiff
joe t replied to alice johnson on 14-Apr-09 08:06 AM

that would be great.

i did find some DLLImport method stubs, but i have the following problems:

1. if i use the libtiff3.dll, i can not link to it no matter what: it always says it can not find it even if it is in the /system32 or executable directory.

2. so i started using the older libtiff.dll, and this works fine EXCEPT it always tells me there is no entry point for _TIFFmalloc call.  and i need this call!  i tried modifying the method stub to be just malloc, or  _malloc, etc, but can not get it to work.

is the libtiff3.dll just the later version of the libtiff.dll?  i don't care which one i use, but both have seperate problems.


Thanks!

Joe