Skip to content

Commit 3d252cc

Browse files
committed
update
1 parent 5421e20 commit 3d252cc

File tree

8 files changed

+32
-18
lines changed

8 files changed

+32
-18
lines changed

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: go
2+
go:
3+
- 1.7.x
4+
- master
5+
notifications:
6+
recipients:
7+
8+
email:
9+
on_success: change
10+
on_failure: always

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,12 @@ xg_a_h: 450
246246

247247
2. 填入百度 OCR key
248248

249-
打开 util 目录下 const.go 文件,修改如下参数
249+
修改参数
250250

251251
```
252-
BaiduAPIKey = "*****************"
253-
BaiduSecretKey = "*****************"
252+
# 百度OCR API参数
253+
Baidu_API_Key: "**************************"
254+
Baidu_Secret_Key: "**************************"
254255
```
255256

256257
3. 程序运行:

cmd/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ device: android
1717
adb_address: '127.0.0.1:62001'
1818
# ios 设备连接wda的地址
1919
wda_address: '127.0.0.1:8100'
20+
# 百度OCR API参数
21+
Baidu_API_Key: "*****************************"
22+
Baidu_Secret_Key: "**************************"
2023
# 西瓜视频裁剪区域:x,y,w,h
2124
xg_q_x: 30
2225
xg_q_y: 240

ocr.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package Answer
22

33
import (
44
"github.com/henson/Answer/ocr"
5+
"github.com/henson/Answer/util"
56
)
67

78
//Ocr ocr 识别图片文字
@@ -13,6 +14,6 @@ func tesseractOCR() Ocr {
1314
return ocr.NewTesseract()
1415
}
1516

16-
func baiduOCR() Ocr {
17-
return ocr.NewBaidu()
17+
func baiduOCR(cfg *util.Config) Ocr {
18+
return ocr.NewBaidu(cfg)
1819
}

ocr/baidu.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"sync"
99
"time"
1010

11-
1211
"github.com/henson/Answer/util"
1312
)
1413

@@ -34,10 +33,10 @@ type wordsResults struct {
3433
}
3534

3635
//NewBaidu new
37-
func NewBaidu() *Baidu {
36+
func NewBaidu(cfg *util.Config) *Baidu {
3837
baidu := new(Baidu)
39-
baidu.apiKey = util.BaiduAPIKey
40-
baidu.secretKey = util.BaiduSecretKey
38+
baidu.apiKey = cfg.BaiduAPIKey
39+
baidu.secretKey = cfg.BaiduSecretKey
4140
return baidu
4241
}
4342

process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func answerQuestion(sc Screenshot, cfg *util.Config) {
100100
go func() {
101101
defer wig.Done()
102102
//answerText, err := baiduOCR().GetText(util.AnswerImage)
103-
answerText, err := baiduOCR().GetText(<-imgChan2)
103+
answerText, err := baiduOCR(cfg).GetText(<-imgChan2)
104104
if err != nil {
105105
log.Errorf("识别答案失败,%v", err.Error())
106106
return

util/config.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import (
99

1010
//Config 全局配置
1111
type Config struct {
12-
Debug bool `yaml:"debug"`
13-
APP string `yaml:"app"`
14-
Auto bool `yaml:"automatic"`
15-
Device string `yaml:"device"`
16-
AdbAddress string `yaml:"adb_address"`
17-
WdaAddress string `yaml:"wda_address"`
12+
Debug bool `yaml:"debug"`
13+
APP string `yaml:"app"`
14+
Auto bool `yaml:"automatic"`
15+
Device string `yaml:"device"`
16+
AdbAddress string `yaml:"adb_address"`
17+
WdaAddress string `yaml:"wda_address"`
18+
BaiduAPIKey string `yaml:"Baidu_API_Key"`
19+
BaiduSecretKey string `yaml:"Baidu_Secret_Key"`
1820

1921
//西瓜视频截图题目位置
2022
XgQx int `yaml:"xg_q_x"`

util/const.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const (
99
AnswerImage = ImagePath + "answer.png"
1010

1111
BaiduAccessTokenKey = "qanswer_baidu_access_token"
12-
BaiduAPIKey = "**************************"
13-
BaiduSecretKey = "**************************"
1412

1513
QuestionInCache = "something else"
1614
)

0 commit comments

Comments
 (0)