feat: get all close buttons from CV

This commit is contained in:
lilong.129
2023-09-21 21:31:10 +08:00
parent 777912f501
commit b5612dbb2a
2 changed files with 31 additions and 28 deletions
+15 -17
View File
@@ -89,22 +89,20 @@ type ClosePopupsResult struct {
} }
type PopupInfo struct { type PopupInfo struct {
CloseStatus string `json:"close_status"` // found/success/fail CloseStatus string `json:"close_status"` // found/success/fail
Type string `json:"type"` RetryCount int `json:"retry_count"`
Text string `json:"text"` CloseBox Box `json:"close_box"` // CV 识别的弹窗关闭按钮(弹窗存在 && 关闭按钮存在)
RetryCount int `json:"retry_count"` ClosePoints []PointF `json:"close_points,omitempty"` // CV 识别的所有关闭按钮(仅关闭按钮,可能存在多个)
PicName string `json:"pic_name"`
PicURL string `json:"pic_url"`
PopupArea Box `json:"popup_area"`
CloseArea Box `json:"close_area"`
} }
func (p *PopupInfo) isIdentical(lastPopup *PopupInfo) bool { func (p *PopupInfo) isIdentical(lastPopup *PopupInfo) bool {
if lastPopup == nil || lastPopup.PopupArea.IsEmpty() { if lastPopup == nil {
return false return false
} }
if lastPopup.CloseBox.IsEmpty() {
if !p.CloseArea.IsIdentical(lastPopup.CloseArea) { return false
}
if !p.CloseBox.IsIdentical(lastPopup.CloseBox) {
lastPopup.CloseStatus = CloseStatusSuccess lastPopup.CloseStatus = CloseStatusSuccess
return false return false
} }
@@ -115,10 +113,7 @@ func (p *PopupInfo) isIdentical(lastPopup *PopupInfo) bool {
} }
func (p *PopupInfo) exists() bool { func (p *PopupInfo) exists() bool {
if p.PopupArea.IsEmpty() || p.CloseArea.IsEmpty() { return !p.CloseBox.IsEmpty()
return false
}
return true
} }
func (dExt *DriverExt) ClosePopups(options ...ActionOption) error { func (dExt *DriverExt) ClosePopups(options ...ActionOption) error {
@@ -144,7 +139,10 @@ func (dExt *DriverExt) ClosePopupsHandler(options ...ActionOption) error {
var lastPopup *PopupInfo var lastPopup *PopupInfo
for retryCount := 0; retryCount < maxRetryTimes; retryCount++ { for retryCount := 0; retryCount < maxRetryTimes; retryCount++ {
screenResult, err := dExt.GetScreenResult( screenResult, err := dExt.GetScreenResult(
WithScreenShotClosePopups(true), WithScreenShotUpload(true)) WithScreenShotUpload(true),
WithScreenShotClosePopups(true),
WithScreenShotUITypes("close"), // get all close buttons
)
if err != nil { if err != nil {
log.Error().Err(err).Msg("get screen result failed for popup handler") log.Error().Err(err).Msg("get screen result failed for popup handler")
continue continue
@@ -181,7 +179,7 @@ func (dExt *DriverExt) tapPopupHandler(popup *PopupInfo) error {
} }
popup.CloseStatus = CloseStatusFound popup.CloseStatus = CloseStatusFound
popupClose := popup.CloseArea popupClose := popup.CloseBox
if popupClose.IsEmpty() { if popupClose.IsEmpty() {
log.Error(). log.Error().
Interface("popup", popup). Interface("popup", popup).
+16 -11
View File
@@ -67,9 +67,9 @@ type ImageResult struct {
// Media(媒体) // Media(媒体)
// Chat(语音) // Chat(语音)
// Event(赛事) // Event(赛事)
LiveType string `json:"liveType,omitempty"` // 直播间类型 LiveType string `json:"liveType,omitempty"` // 直播间类型
UIResult UIResultMap `json:"uiResult,omitempty"` // 图标检测 UIResult UIResultMap `json:"uiResult,omitempty"` // 图标检测
CPResult *ClosePopupsResult `json:"closeResult,omitempty"` // 弹窗按钮检测 ClosePopupsResult *ClosePopupsResult `json:"closeResult,omitempty"` // 弹窗按钮检测
} }
type APIResponseImage struct { type APIResponseImage struct {
@@ -407,15 +407,20 @@ func (dExt *DriverExt) GetScreenResult(options ...ActionOption) (screenResult *S
screenResult.UploadedURL = imageResult.URL screenResult.UploadedURL = imageResult.URL
screenResult.Icons = imageResult.UIResult screenResult.Icons = imageResult.UIResult
if actionOptions.ScreenShotWithClosePopups && imageResult.CPResult != nil { if actionOptions.ScreenShotWithClosePopups {
screenResult.Popup = &PopupInfo{ popup := &PopupInfo{}
Type: imageResult.CPResult.Type,
Text: imageResult.CPResult.Text, closeResult := imageResult.ClosePopupsResult
PicName: imagePath, if closeResult != nil && !closeResult.PopupArea.IsEmpty() && !closeResult.CloseArea.IsEmpty() {
PicURL: imageResult.URL, popup.CloseBox = closeResult.CloseArea
PopupArea: imageResult.CPResult.PopupArea,
CloseArea: imageResult.CPResult.CloseArea,
} }
closeAreas, _ := imageResult.UIResult.FilterUIResults([]string{"close"})
for _, closeArea := range closeAreas {
popup.ClosePoints = append(popup.ClosePoints, closeArea.Center())
}
screenResult.Popup = popup
} }
} }