forked from tleyden/open-ocr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ocr_request.go
45 lines (37 loc) · 1.32 KB
/
ocr_request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package ocrworker
import "fmt"
type OcrRequest struct {
ImgUrl string `json:"img_url"`
EngineType OcrEngineType `json:"engine"`
ImgBytes []byte `json:"img_bytes"`
PreprocessorChain []string `json:"preprocessors"`
PreprocessorArgs map[string]interface{} `json:"preprocessor-args"`
EngineArgs map[string]interface{} `json:"engine_args"`
// decode ocr in http handler rather than putting in queue
InplaceDecode bool `json:"inplace_decode"`
}
// figure out the next pre-processor routing key to use (if any).
// if we have finished with the pre-processors, then use the processorRoutingKey
func (ocrRequest *OcrRequest) nextPreprocessor(processorRoutingKey string) string {
if len(ocrRequest.PreprocessorChain) == 0 {
return processorRoutingKey
} else {
var x string
s := ocrRequest.PreprocessorChain
x, s = s[len(s)-1], s[:len(s)-1]
ocrRequest.PreprocessorChain = s
return x
}
}
func (ocrRequest *OcrRequest) downloadImgUrl() error {
bytes, err := url2bytes(ocrRequest.ImgUrl)
if err != nil {
return err
}
ocrRequest.ImgBytes = bytes
ocrRequest.ImgUrl = ""
return nil
}
func (o OcrRequest) String() string {
return fmt.Sprintf("ImgUrl: %s, EngineType: %s, Preprocessors: %s", o.ImgUrl, o.EngineType, o.PreprocessorChain)
}