change: dump ocr texts as string in summary

This commit is contained in:
lilong.129
2023-04-28 13:23:52 +08:00
parent 37a984c243
commit 2323015755
2 changed files with 8 additions and 7 deletions
+6 -6
View File
@@ -51,8 +51,8 @@ type DriverExt struct {
windowSize Size windowSize Size
frame *bytes.Buffer frame *bytes.Buffer
doneMjpegStream chan bool doneMjpegStream chan bool
OCRService IOCRService // used to get texts from image OCRService IOCRService // used to get texts from image
stepScreenShots map[string]OCRTexts // cache screenshot ocr results, key is image path stepScreenShots map[string]string // cache screenshot ocr results, key is image path, value is dumped OCRTexts
CVArgs CVArgs
} }
@@ -61,7 +61,7 @@ func NewDriverExt(device Device, driver WebDriver) (dExt *DriverExt, err error)
dExt = &DriverExt{ dExt = &DriverExt{
Device: device, Device: device,
Driver: driver, Driver: driver,
stepScreenShots: make(map[string]OCRTexts), stepScreenShots: make(map[string]string),
} }
dExt.doneMjpegStream = make(chan bool, 1) dExt.doneMjpegStream = make(chan bool, 1)
@@ -160,19 +160,19 @@ func (dExt *DriverExt) saveScreenShot(raw *bytes.Buffer, fileName string) (strin
return "", errors.Wrap(err, "encode screenshot image failed") return "", errors.Wrap(err, "encode screenshot image failed")
} }
dExt.stepScreenShots[screenshotPath] = nil dExt.stepScreenShots[screenshotPath] = ""
log.Info().Str("path", screenshotPath).Msg("save screenshot file success") log.Info().Str("path", screenshotPath).Msg("save screenshot file success")
return screenshotPath, nil return screenshotPath, nil
} }
func (dExt *DriverExt) GetScreenShots() map[string]OCRTexts { func (dExt *DriverExt) GetScreenShots() map[string]string {
defer func() { defer func() {
for key := range dExt.stepScreenShots { for key := range dExt.stepScreenShots {
delete(dExt.stepScreenShots, key) delete(dExt.stepScreenShots, key)
} }
}() }()
copied := make(map[string]OCRTexts) copied := make(map[string]string)
for key, value := range dExt.stepScreenShots { for key, value := range dExt.stepScreenShots {
copied[key] = value copied[key] = value
} }
+2 -1
View File
@@ -291,7 +291,8 @@ func (dExt *DriverExt) GetScreenTextsByOCR() (texts OCRTexts, err error) {
return return
} }
dExt.stepScreenShots[imagePath] = ocrTexts o, _ := json.Marshal(ocrTexts)
dExt.stepScreenShots[imagePath] = string(o)
return ocrTexts, nil return ocrTexts, nil
} }