mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-03 14:59:38 +08:00
refactor: OCRService.GetTexts remove options
This commit is contained in:
@@ -268,7 +268,7 @@ func (dExt *DriverExt) DoAction(action MobileAction) error {
|
|||||||
var point PointF
|
var point PointF
|
||||||
findTexts := func(d *DriverExt) error {
|
findTexts := func(d *DriverExt) error {
|
||||||
var err error
|
var err error
|
||||||
ocrTexts, err := d.GetScreenTextsByOCR(scopeOption)
|
ocrTexts, err := d.GetScreenTextsByOCR()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,6 +62,13 @@ func (t OCRTexts) FindText(text string, options ...DataOption) (
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if text in scope
|
||||||
|
if rect.Min.X < dataOptions.Scope[0] || rect.Max.X > dataOptions.Scope[2] ||
|
||||||
|
rect.Min.Y < dataOptions.Scope[1] || rect.Max.Y > dataOptions.Scope[3] {
|
||||||
|
// not in scope
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
rects = append(rects, rect)
|
rects = append(rects, rect)
|
||||||
|
|
||||||
// contains text while not match exactly
|
// contains text while not match exactly
|
||||||
@@ -121,6 +128,7 @@ func newVEDEMOCRService() (*veDEMOCRService, error) {
|
|||||||
return &veDEMOCRService{}, nil
|
return &veDEMOCRService{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// veDEMOCRService implements IOCRService interface
|
||||||
type veDEMOCRService struct{}
|
type veDEMOCRService struct{}
|
||||||
|
|
||||||
func (s *veDEMOCRService) getOCRResult(imageBuf *bytes.Buffer) ([]OCRResult, error) {
|
func (s *veDEMOCRService) getOCRResult(imageBuf *bytes.Buffer) ([]OCRResult, error) {
|
||||||
@@ -205,7 +213,7 @@ func (s *veDEMOCRService) getOCRResult(imageBuf *bytes.Buffer) ([]OCRResult, err
|
|||||||
return ocrResult.OCRResult, nil
|
return ocrResult.OCRResult, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *veDEMOCRService) GetTexts(imageBuf *bytes.Buffer, options ...DataOption) (
|
func (s *veDEMOCRService) GetTexts(imageBuf *bytes.Buffer) (
|
||||||
ocrTexts OCRTexts, err error) {
|
ocrTexts OCRTexts, err error) {
|
||||||
|
|
||||||
ocrResults, err := s.getOCRResult(imageBuf)
|
ocrResults, err := s.getOCRResult(imageBuf)
|
||||||
@@ -214,8 +222,6 @@ func (s *veDEMOCRService) GetTexts(imageBuf *bytes.Buffer, options ...DataOption
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dataOptions := NewDataOptions(options...)
|
|
||||||
|
|
||||||
for _, ocrResult := range ocrResults {
|
for _, ocrResult := range ocrResults {
|
||||||
rect := image.Rectangle{
|
rect := image.Rectangle{
|
||||||
// ocrResult.Points 顺序:左上 -> 右上 -> 右下 -> 左下
|
// ocrResult.Points 顺序:左上 -> 右上 -> 右下 -> 左下
|
||||||
@@ -229,18 +235,13 @@ func (s *veDEMOCRService) GetTexts(imageBuf *bytes.Buffer, options ...DataOption
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if text in scope
|
|
||||||
if rect.Min.X < dataOptions.Scope[0] || rect.Max.X > dataOptions.Scope[2] ||
|
|
||||||
rect.Min.Y < dataOptions.Scope[1] || rect.Max.Y > dataOptions.Scope[3] {
|
|
||||||
// not in scope
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
ocrTexts = append(ocrTexts, OCRText{
|
ocrTexts = append(ocrTexts, OCRText{
|
||||||
Text: ocrResult.Text,
|
Text: ocrResult.Text,
|
||||||
Rect: rect,
|
Rect: rect,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug().Interface("texts", ocrTexts).Msg("get screen texts by veDEM OCR")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,28 +271,27 @@ func getLogID(header http.Header) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type IOCRService interface {
|
type IOCRService interface {
|
||||||
GetTexts(imageBuf *bytes.Buffer, options ...DataOption) (ocrTexts OCRTexts, err error)
|
GetTexts(imageBuf *bytes.Buffer) (texts OCRTexts, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) GetScreenTextsByOCR(options ...DataOption) (texts OCRTexts, err error) {
|
func (dExt *DriverExt) GetScreenTextsByOCR() (texts OCRTexts, err error) {
|
||||||
var bufSource *bytes.Buffer
|
var bufSource *bytes.Buffer
|
||||||
if bufSource, err = dExt.TakeScreenShot(
|
if bufSource, err = dExt.TakeScreenShot(
|
||||||
builtin.GenNameWithTimestamp("screenshot_%d_ocr")); err != nil {
|
builtin.GenNameWithTimestamp("screenshot_%d_ocr")); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ocrTexts, err := dExt.OCRService.GetTexts(bufSource, options...)
|
ocrTexts, err := dExt.OCRService.GetTexts(bufSource)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("GetScreenTextsByOCR failed")
|
log.Error().Err(err).Msg("GetScreenTextsByOCR failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Interface("texts", ocrTexts).Msg("get screen texts by OCR")
|
|
||||||
return ocrTexts, nil
|
return ocrTexts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dExt *DriverExt) FindScreenTextByOCR(text string, options ...DataOption) (point PointF, err error) {
|
func (dExt *DriverExt) FindScreenTextByOCR(text string, options ...DataOption) (point PointF, err error) {
|
||||||
ocrTexts, err := dExt.GetScreenTextsByOCR(options...)
|
ocrTexts, err := dExt.GetScreenTextsByOCR()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user