Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
henson committed Jan 22, 2018
1 parent 5421e20 commit 3d252cc
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 18 deletions.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: go
go:
- 1.7.x
- master
notifications:
recipients:
- [email protected]
email:
on_success: change
on_failure: always
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ xg_a_h: 450
2. 填入百度 OCR key
打开 util 目录下 const.go 文件,修改如下参数
修改参数
```
BaiduAPIKey = "*****************"
BaiduSecretKey = "*****************"
# 百度OCR API参数
Baidu_API_Key: "**************************"
Baidu_Secret_Key: "**************************"
```
3. 程序运行:
Expand Down
3 changes: 3 additions & 0 deletions cmd/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ device: android
adb_address: '127.0.0.1:62001'
# ios 设备连接wda的地址
wda_address: '127.0.0.1:8100'
# 百度OCR API参数
Baidu_API_Key: "*****************************"
Baidu_Secret_Key: "**************************"
# 西瓜视频裁剪区域:x,y,w,h
xg_q_x: 30
xg_q_y: 240
Expand Down
5 changes: 3 additions & 2 deletions ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package Answer

import (
"github.com/henson/Answer/ocr"
"github.com/henson/Answer/util"
)

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

func baiduOCR() Ocr {
return ocr.NewBaidu()
func baiduOCR(cfg *util.Config) Ocr {
return ocr.NewBaidu(cfg)
}
7 changes: 3 additions & 4 deletions ocr/baidu.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"sync"
"time"


"github.com/henson/Answer/util"
)

Expand All @@ -34,10 +33,10 @@ type wordsResults struct {
}

//NewBaidu new
func NewBaidu() *Baidu {
func NewBaidu(cfg *util.Config) *Baidu {
baidu := new(Baidu)
baidu.apiKey = util.BaiduAPIKey
baidu.secretKey = util.BaiduSecretKey
baidu.apiKey = cfg.BaiduAPIKey
baidu.secretKey = cfg.BaiduSecretKey
return baidu
}

Expand Down
2 changes: 1 addition & 1 deletion process.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func answerQuestion(sc Screenshot, cfg *util.Config) {
go func() {
defer wig.Done()
//answerText, err := baiduOCR().GetText(util.AnswerImage)
answerText, err := baiduOCR().GetText(<-imgChan2)
answerText, err := baiduOCR(cfg).GetText(<-imgChan2)
if err != nil {
log.Errorf("识别答案失败,%v", err.Error())
return
Expand Down
14 changes: 8 additions & 6 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (

//Config 全局配置
type Config struct {
Debug bool `yaml:"debug"`
APP string `yaml:"app"`
Auto bool `yaml:"automatic"`
Device string `yaml:"device"`
AdbAddress string `yaml:"adb_address"`
WdaAddress string `yaml:"wda_address"`
Debug bool `yaml:"debug"`
APP string `yaml:"app"`
Auto bool `yaml:"automatic"`
Device string `yaml:"device"`
AdbAddress string `yaml:"adb_address"`
WdaAddress string `yaml:"wda_address"`
BaiduAPIKey string `yaml:"Baidu_API_Key"`
BaiduSecretKey string `yaml:"Baidu_Secret_Key"`

//西瓜视频截图题目位置
XgQx int `yaml:"xg_q_x"`
Expand Down
2 changes: 0 additions & 2 deletions util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const (
AnswerImage = ImagePath + "answer.png"

BaiduAccessTokenKey = "qanswer_baidu_access_token"
BaiduAPIKey = "**************************"
BaiduSecretKey = "**************************"

QuestionInCache = "something else"
)

0 comments on commit 3d252cc

Please sign in to comment.