From d64f6151d919cc0493b202f2e9fc7000f29a1827 Mon Sep 17 00:00:00 2001 From: buyuxiang <347586493@qq.com> Date: Wed, 28 Jun 2023 13:03:14 +0800 Subject: [PATCH] tap_cv supports WithDataScope --- hrp/internal/version/VERSION | 2 +- hrp/pkg/uixt/algorithm.go | 2 +- hrp/pkg/uixt/ext.go | 21 ++++++++++++++++++--- hrp/pkg/uixt/ui_vedem.go | 10 ++++------ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/hrp/internal/version/VERSION b/hrp/internal/version/VERSION index c63f5e80..feba9cc8 100644 --- a/hrp/internal/version/VERSION +++ b/hrp/internal/version/VERSION @@ -1 +1 @@ -v4.3.3.2306151200 \ No newline at end of file +v4.3.3.2306281303 \ No newline at end of file diff --git a/hrp/pkg/uixt/algorithm.go b/hrp/pkg/uixt/algorithm.go index ac6c11c5..ac517ddb 100644 --- a/hrp/pkg/uixt/algorithm.go +++ b/hrp/pkg/uixt/algorithm.go @@ -203,7 +203,7 @@ func (dExt *DriverExt) FindDetectUIRectInUIKit(uiTypes []string, options ...Data return 0, 0, 0, 0, err } var rect image.Rectangle - rect, err = service.FindUI(uiTypes, bufSource.Bytes()) + rect, err = service.FindUI(uiTypes, bufSource.Bytes(), options...) if err != nil { return 0, 0, 0, 0, err } diff --git a/hrp/pkg/uixt/ext.go b/hrp/pkg/uixt/ext.go index ec0f1ca0..3c055f19 100644 --- a/hrp/pkg/uixt/ext.go +++ b/hrp/pkg/uixt/ext.go @@ -614,15 +614,30 @@ func (dExt *DriverExt) DoAction(action MobileAction) error { return fmt.Errorf("invalid %s params: %v", ACTION_TapByOCR, action.Params) case ACTION_TapByCV: if imagePath, ok := action.Params.(string); ok { - return dExt.TapByCV(imagePath, WithDataIdentifier(action.Identifier), WithDataIgnoreNotFoundError(action.IgnoreNotFoundError), WithDataIndex(action.Index)) + return dExt.TapByCV( + imagePath, + WithDataIdentifier(action.Identifier), + WithDataIgnoreNotFoundError(action.IgnoreNotFoundError), + WithDataIndex(action.Index), + WithDataScope(dExt.getAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3])), + ) } if uiParams, ok := action.Params.([]interface{}); ok { var uiTypes []string for _, uiParam := range uiParams { - uiType, _ := uiParam.(string) + uiType, ok := uiParam.(string) + if !ok { + continue + } uiTypes = append(uiTypes, uiType) } - return dExt.TapByUIDetection(uiTypes, WithDataIdentifier(action.Identifier), WithDataIgnoreNotFoundError(action.IgnoreNotFoundError), WithDataIndex(action.Index)) + return dExt.TapByUIDetection( + uiTypes, + WithDataIdentifier(action.Identifier), + WithDataIgnoreNotFoundError(action.IgnoreNotFoundError), + WithDataIndex(action.Index), + WithDataScope(dExt.getAbsScope(action.Scope[0], action.Scope[1], action.Scope[2], action.Scope[3])), + ) } return fmt.Errorf("invalid %s params: %v", ACTION_TapByCV, action.Params) case ACTION_DoubleTapXY: diff --git a/hrp/pkg/uixt/ui_vedem.go b/hrp/pkg/uixt/ui_vedem.go index c136a058..eba8cc23 100644 --- a/hrp/pkg/uixt/ui_vedem.go +++ b/hrp/pkg/uixt/ui_vedem.go @@ -152,15 +152,13 @@ func (s *veDEMUIService) FindUI(uiTypes []string, byteSource []byte, options ... } } if len(uiResult) == 0 { - err = fmt.Errorf("UI types %v not detected", uiTypes) - log.Error().Err(err).Msg("getUIResult failed") - return + return image.Rectangle{}, errors.Wrap(code.CVImageNotFoundError, + fmt.Sprintf("ui types %v not found", uiTypes)) } var rects []image.Rectangle for _, box := range uiResult { rect = image.Rectangle{ - // cvResult.Points 顺序:左上 -> 右上 -> 右下 -> 左下 Min: image.Point{ X: int(box.Point.X), Y: int(box.Point.Y), @@ -182,7 +180,7 @@ func (s *veDEMUIService) FindUI(uiTypes []string, byteSource []byte, options ... if len(rects) == 0 { return image.Rectangle{}, errors.Wrap(code.CVImageNotFoundError, - fmt.Sprintf("image not found")) + fmt.Sprintf("ui found, but out of scope %v", data.Scope)) } // get index @@ -197,7 +195,7 @@ func (s *veDEMUIService) FindUI(uiTypes []string, byteSource []byte, options ... // index out of range if idx >= len(rects) { return image.Rectangle{}, errors.Wrap(code.CVImageNotFoundError, - fmt.Sprintf("image found, index %d out of range", idx)) + fmt.Sprintf("ui found, but index %d out of range", idx)) } return rects[idx], nil