Skip to content

Data not being processed correctly #5

@maxpowel

Description

@maxpowel

Hi, I found other image that is not being processed correctly.

This attachment contains the original data, the pbm created by fax crate and the tiff to preview it
stream_6.zip

Looks similar to #2 because it is partially processed and at some point boom!

Using this go snippet you can get this output (it is similar to the one in other ticket but with with newlines calculated instead of hardcoded). The library source code is at https://github.com/golang/image/blob/master/ccitt/reader.go
image

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"

	"golang.org/x/image/ccitt"
)

func byteToBits(b byte) string {
	// Convertir el byte a una cadena de bits
	bits := strconv.FormatUint(uint64(b), 2)

	// Añadir ceros a la izquierda si la cadena de bits es menor a 8 caracteres
	for len(bits) < 8 {
		bits = "0" + bits
	}
	return bits
}

func main() {
	file, err := os.Open("/media/storage/ocr/elemento")
	if err != nil {
		fmt.Println("Error al abrir la imagen CCITT:", err)
		return
	}
	defer file.Close()
	fmt.Println("File open")
	fileReader := bufio.NewReader(file)

	cols := 264

	rows := 100

	blackIs1 := false
	encodedByteAlign := false

	opts := &ccitt.Options{Invert: blackIs1, Align: encodedByteAlign}
	mode := ccitt.Group4

	rd := ccitt.NewReader(fileReader, ccitt.MSB, mode, cols, rows, opts)

	var b bytes.Buffer
	written, err := io.Copy(&b, rd)
	if err != nil {
		fmt.Println("Error al proc:", err)
	} else {
		fmt.Println("OK written", written)
		index := 0
		for v, e := b.ReadByte(); v != 'e' && e == nil; v, e = b.ReadByte() {
			bits := byteToBits(v)
			fmt.Print(strings.Replace(strings.Replace(bits, "1", " ", -1), "0", "*", -1))
			//fmt.Print(bits)
			index += 1
			if index%(cols/8) == 0 {
				fmt.Println("")
				index = 0
			}
		}

	}
}

Thank you so much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions