fix: run ocr alone without opencv

This commit is contained in:
debugtalk
2022-09-21 17:50:08 +08:00
parent 937b48236e
commit 976e715357
11 changed files with 42 additions and 24 deletions

View File

@@ -28,6 +28,10 @@ You can get more installation introduction on [hybridgroup/gocv].
OCR API is a paid service, you need to pre-purchase and configure the account key.
```bash
$ make build tags=ocr
```
## Thanks
This uixt module is initially forked from [electricbubble/gwda-ext-opencv] and made a lot of changes.

View File

@@ -22,7 +22,6 @@ import (
type TemplateMatchMode int
type CVArgs struct {
scale float64
matchMode TemplateMatchMode
threshold float64
}
@@ -46,6 +45,7 @@ type DriverExt struct {
windowSize gwda.Size
frame *bytes.Buffer
doneMjpegStream chan bool
scale float64
CVArgs
}
@@ -60,6 +60,10 @@ func extend(driver gwda.WebDriver) (dExt *DriverExt, err error) {
return nil, errors.Wrap(err, "failed to get windows size")
}
if dExt.scale, err = dExt.Scale(); err != nil {
return nil, err
}
return dExt, nil
}
@@ -213,6 +217,12 @@ func (dExt *DriverExt) FindUIRectInUIKit(search string) (x, y, width, height flo
return dExt.FindImageRectInUIKit(search)
}
func (dExt *DriverExt) MappingToRectInUIKit(rect image.Rectangle) (x, y, width, height float64) {
x, y = float64(rect.Min.X)/dExt.scale, float64(rect.Min.Y)/dExt.scale
width, height = float64(rect.Dx())/dExt.scale, float64(rect.Dy())/dExt.scale
return
}
func (dExt *DriverExt) PerformTouchActions(touchActions *gwda.TouchActions) error {
return dExt.PerformAppiumTouchActions(touchActions)
}

View File

@@ -4,6 +4,7 @@ package uixt
import (
"image"
"sort"
"github.com/electricbubble/gwda"
)

View File

@@ -4,11 +4,15 @@ package uixt
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"image"
"io/ioutil"
"mime/multipart"
"net/http"
"strings"
"time"
)
var client = &http.Client{

View File

@@ -22,8 +22,3 @@ func (dExt *DriverExt) FindImageRectInUIKit(imagePath string) (x, y, width, heig
log.Fatal().Msg("opencv is not supported")
return
}
func (dExt *DriverExt) MappingToRectInUIKit(rect image.Rectangle) (x, y, width, height float64) {
log.Fatal().Msg("opencv is not supported")
return
}

View File

@@ -53,10 +53,6 @@ func Extend(driver gwda.WebDriver, options ...CVOption) (dExt *DriverExt, err er
option(&dExt.CVArgs)
}
if dExt.scale, err = dExt.Scale(); err != nil {
return nil, err
}
if dExt.threshold == 0 {
dExt.threshold = 0.95 // default threshold
}
@@ -149,9 +145,3 @@ func getBufFromDisk(name string) (*bytes.Buffer, error) {
}
return bytes.NewBuffer(all), nil
}
func (dExt *DriverExt) MappingToRectInUIKit(rect image.Rectangle) (x, y, width, height float64) {
x, y = float64(rect.Min.X)/dExt.scale, float64(rect.Min.Y)/dExt.scale
width, height = float64(rect.Dx())/dExt.scale, float64(rect.Dy())/dExt.scale
return
}