문제

Tesseract ORC가 이미지 파일을 통해 실행하여 내용을 스캔하도록합니다.

문제는 Tesseract가 TIFF를 요구할뿐만 아니라 TIFF 파일이 특정 형식으로되어야한다는 것으로 보입니다.

정상적인 tiff 파일 만 있으면 다음과 같습니다.

root@toshiba:~/Desktop# tesseract crap.tif crap.txt
Tesseract Open Source OCR Engine
check_legal_image_size:Error:Only 1,2,4,5,6,8 bpp are supported:32
Segmentation fault
.

지금까지 나는 해독제를 찾을 수있었습니다.
김프를 사용하여 이미지> 모드> 인덱스로 이동하여 "최적 팔레트 생성", "최대 색 수"를 256으로 설정합니다. 여기에 이미지 설명을 입력하십시오>


그런 다음 "다른 이름으로 저장"전에 하나의 트릭을해야합니다.


레이어로 가기> 투명도> 알파 채널 제거, TIF 이미지가 투명성을 가질 수 없기 때문에 투명성을 제거합니다.

여기에 이미지 설명

이제 문제는 내 입력 이미지가 C #에서 비롯되며 AFORGE.NET 이미지 분석 필터로 전처리됩니다.

나는 또한 Libtiff의 .NET 포트를 발견하고 여기에 색상 팔레트가있는 이미지를 작성하는 방법의 예입니다. http://bitmiracle.com/libtiff/ 도움말 / 제작 - 팔레트 - (컬러 맵) .aspx

그러나 Source Tiff (잘못된 팔레트가있는 것)에서 데이터를 대상 TIFF (올바른 팔레트 형식으로)로 가져 오는 방법을 모르겠습니다 ...

도움이 되었습니까?

해결책

tesseract가 그레이 스케일 tiffs와 잘 어울리는 것을 들었습니다.

그래서 TIFF 이미지를 그레이 스케일로 변환하기 위해 코드를 시도하십시오.

using (Tiff tif = Tiff.Open(@"input.tif", "r"))
{
    FieldValue[] value = tif.GetField(TiffTag.IMAGEWIDTH);
    int width = value[0].ToInt();

    value = tif.GetField(TiffTag.IMAGELENGTH);
    int height = value[0].ToInt();

    int xresolution = -1;
    value = tif.GetField(TiffTag.XRESOLUTION);
    if (value != null)
        xresolution = value[0].ToInt();

    int yresolution = -1;
    value = tif.GetField(TiffTag.YRESOLUTION);
    if (value != null)
        yresolution = value[0].ToInt();

    int[] raster = new int[height * width];
    if (!tif.ReadRGBAImageOriented(width, height, raster, Orientation.TOPLEFT))
    {
        System.Windows.Forms.MessageBox.Show("Could not read image");
        return;
    }

    string fileName = "grayscale.tif";
    using (Tiff output = Tiff.Open(fileName, "w"))
    {
        output.SetField(TiffTag.IMAGEWIDTH, width);
        output.SetField(TiffTag.IMAGELENGTH, height);
        output.SetField(TiffTag.ROWSPERSTRIP, 1);
        output.SetField(TiffTag.SAMPLESPERPIXEL, 1);
        output.SetField(TiffTag.BITSPERSAMPLE, 8);
        output.SetField(TiffTag.PLANARCONFIG, PlanarConfig.CONTIG);
        output.SetField(TiffTag.COMPRESSION, Compression.LZW);
        output.SetField(TiffTag.FILLORDER, FillOrder.MSB2LSB);
        output.SetField(TiffTag.PHOTOMETRIC, Photometric.MINISBLACK);

        if (xresolution != -1 && yresolution != -1)
        {
            output.SetField(TiffTag.XRESOLUTION, xresolution);
            output.SetField(TiffTag.YRESOLUTION, yresolution);
        }

        byte[] samples = new byte[width];
        for (int y = 0, index = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                int rgb = raster[index++];

                // compute pixel brightness taking human eye's sensitivity
                // to each of red, green and blue colors into account
                byte gray = (byte)(Tiff.GetR(rgb) * 0.299 + Tiff.GetG(rgb) * 0.587 + Tiff.GetB(rgb) * 0.114);

                // Alternative formulas for RGB -> Gray conversion

                //byte gray = (byte)(Tiff.GetR(rgb) * 0.2125 + Tiff.GetG(rgb) * 0.7154 + Tiff.GetB(rgb) * 0.0721);
                //byte gray = (byte)((Tiff.GetR(rgb) + Tiff.GetG(rgb) + Tiff.GetB(rgb)) / 3);

                samples[x] = gray;
            }

            output.WriteEncodedStrip(y, samples, samples.Length);
        }
    }
}
.

잘하면, 그것은 트릭을 할 것입니다.

다른 팁

Tesseract와 동일한 문제가 있었지만 조언 덕분에 김프를 사용하여 색상 파일에서 GreyScale로 변경했습니다.이는 명령 이미지 모드 - GreyScale을 사용하여 쉽게 수행 한 다음 TIF로 다시 저장합니다.이렇게하면 이미지 라인을 사용하여 이미지 문제를 해결하기를 원하지 않는 사람이 도움이됩니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top