replaycli-go/api/ocr/cli.go

150 lines
4.4 KiB
Go
Raw Normal View History

2021-10-31 09:37:05 +00:00
package ocr
import (
"encoding/xml"
"go.digitalcircle.com.br/open/replaycli-go/api"
)
type AltoString struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
HPOS int `xml:"HPOS,attr"`
VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
WC float64 `xml:"WC,attr"`
CONTENT string `xml:"CONTENT,attr"`
}
type AltoSP struct {
Text string `xml:",chardata"`
WIDTH int `xml:"WIDTH,attr"`
VPOS int `xml:"VPOS,attr"`
HPOS int `xml:"HPOS,attr"`
}
type AltoTextLine struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
HPOS string `xml:"HPOS,attr"`
VPOS string `xml:"VPOS,attr"`
WIDTH string `xml:"WIDTH,attr"`
HEIGHT string `xml:"HEIGHT,attr"`
String []AltoString `xml:"String"`
SP []AltoSP `xml:"SP"`
}
type AltoTextBlock struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
HPOS int `xml:"HPOS,attr"`
VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
TextLine []AltoTextLine `xml:"TextLine"`
}
type AltoComposedBlock struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
HPOS int `xml:"HPOS,attr"`
VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
TextBlock []AltoTextBlock `xml:"TextBlock"`
}
type AltoPrintSpace struct {
Text string `xml:",chardata"`
HPOS int `xml:"HPOS,attr"`
VPOS int `xml:"VPOS,attr"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
ComposedBlock []AltoComposedBlock `xml:"ComposedBlock"`
}
type AltoPage struct {
Text string `xml:",chardata"`
WIDTH int `xml:"WIDTH,attr"`
HEIGHT int `xml:"HEIGHT,attr"`
PHYSICALIMGNR string `xml:"PHYSICAL_IMG_NR,attr"`
ID string `xml:"ID,attr"`
PrintSpace AltoPrintSpace `xml:"PrintSpace"`
}
type AltoDescription struct {
Text string `xml:",chardata"`
MeasurementUnit string `xml:"MeasurementUnit"`
SourceImageInformation struct {
Text string `xml:",chardata"`
FileName string `xml:"fileName"`
} `xml:"sourceImageInformation"`
OCRProcessing struct {
Text string `xml:",chardata"`
ID string `xml:"ID,attr"`
OcrProcessingStep struct {
Text string `xml:",chardata"`
ProcessingSoftware struct {
Text string `xml:",chardata"`
SoftwareName string `xml:"softwareName"`
} `xml:"processingSoftware"`
} `xml:"ocrProcessingStep"`
} `xml:"OCRProcessing"`
}
type AltoLayout struct {
Text string `xml:",chardata"`
Page AltoPage `xml:"Page"`
}
type Alto struct {
XMLName xml.Name `xml:"alto"`
Text string `xml:",chardata"`
Xmlns string `xml:"xmlns,attr"`
Xlink string `xml:"xlink,attr"`
Xsi string `xml:"xsi,attr"`
SchemaLocation string `xml:"schemaLocation,attr"`
Description AltoDescription `xml:"Description"`
Layout AltoLayout `xml:"Layout"`
}
func (a Alto) Strings() []AltoString {
ret := make([]AltoString, 0)
for _, v := range a.Layout.Page.PrintSpace.ComposedBlock {
for _, v1 := range v.TextBlock {
for _, v2 := range v1.TextLine {
for _, v3 := range v2.String {
ret = append(ret, v3)
}
}
}
}
return ret
}
type Opts struct {
Ver string `json:"ver,omitempty"`
X int `json:"x"`
Y int `json:"y"`
H int `json:"h"`
W int `json:"w"`
Blur float64 `json:"blur"`
Sharpen float64 `json:"sharpen"`
Resizew int `json:"resizew"`
Resizeh int `json:"resizeh"`
Lang string `json:"lang"`
Tempfile string `json:"tempfile"`
Dispid int `json:"d"`
Gray bool `json:"gray"`
Src string `json:"src"`
Bytes []byte `json:"bytes"`
AddRects bool `json:"add_rects"`
}
type Cli struct {
*api.ApiCli
}
func (c *Cli) OCR(opts *Opts) (*Alto, error) {
res := &Alto{}
2021-10-31 22:57:02 +00:00
err := c.HttpCli().JsonPost("/", opts, res)
2021-10-31 09:37:05 +00:00
return res, err
}
func NewCli() *Cli {
2021-10-31 22:56:25 +00:00
ret := &Cli{ApiCli: api.NewApiCli()}
2021-10-31 09:37:05 +00:00
ret.ApiCli.HttpCli().SetBasePath("http://ocr/")
return ret
}