fix: run ocr alone without opencv

This commit is contained in:
debugtalk
2022-09-21 17:50:08 +08:00
parent be41ec8fd7
commit 9004f84791
11 changed files with 42 additions and 24 deletions

View File

@@ -16,7 +16,7 @@ bump: ## bump hrp version, e.g. make bump version=4.0.0
.PHONY: build
build: ## build hrp cli tool
@echo "[info] build hrp cli tool"
@. scripts/build.sh
@. scripts/build.sh $(tags)
.PHONY: install-hooks
install-hooks: ## install git hooks

View File

@@ -64,6 +64,7 @@
{
"method": "swipe_to_tap_text",
"params": "轻触进入直播间",
"identifier": "进入直播间",
"max_retry_times": 10
}
]
@@ -75,7 +76,8 @@
"actions": [
{
"method": "swipe",
"params": "up"
"params": "up",
"identifier": "第一次上划"
},
{
"method": "sleep",
@@ -86,7 +88,8 @@
},
{
"method": "swipe",
"params": "up"
"params": "up",
"identifier": "第二次上划"
},
{
"method": "sleep",

View File

@@ -33,17 +33,20 @@ teststeps:
actions:
- method: swipe_to_tap_text
params: 轻触进入直播间
identifier: 进入直播间
max_retry_times: 10
- name: 向上滑动,等待 10s
ios:
actions:
- method: swipe
params: up
identifier: 第一次上划
- method: sleep
params: 10
- method: screenshot
- method: swipe
params: up
identifier: 第二次上划
- method: sleep
params: 10
- method: screenshot

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
}

View File

@@ -4,8 +4,10 @@
# Usage:
# $ make build
# $ make build tags=ocr
# or
# $ bash cli/scripts/build.sh
# $ bash scripts/build.sh
# $ bash scripts/build.sh ocr
set -e
set -x
@@ -14,9 +16,15 @@ set -x
mkdir -p "output"
bin_path="output/hrp"
# build
# optional build tags: opencv ocr
go build -ldflags '-s -w' -tags ocr -o "$bin_path" hrp/cmd/cli/main.go
tags=$1
# build
if [ -z "$tags" ]; then
go build -ldflags '-s -w' -o "$bin_path" hrp/cmd/cli/main.go
else
go build -ldflags '-s -w' -tags "$tags" -o "$bin_path" hrp/cmd/cli/main.go
fi
# check output and version
ls -lh "$bin_path"

View File

@@ -3,9 +3,9 @@
# release will be triggered on github actions, see .github/workflows/release.yml
# Usage:
# $ make bump version=v0.5.2
# $ make bump version=v4.3.0
# or
# $ bash cli/scripts/bump_version.sh v0.5.2
# $ bash scripts/bump_version.sh v4.3.0
set -e