Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
BYLAppRobot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuyang
BYLAppRobot
Commits
7ea9e582
Commit
7ea9e582
authored
Jan 08, 2019
by
liuyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
APK图片抓取识别及轮播流地址抓取, 客户端增加百度电话号码识别
#BYLSERVER-1438
parent
b31b21f7
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
21 deletions
+34
-21
log4j-1.2.17.jar
app/libs/log4j-1.2.17.jar
+0
-0
Task.kt
app/src/main/java/com/duolebo/blyrobot/data/Task.kt
+19
-7
OcrManager.kt
app/src/main/java/com/duolebo/blyrobot/tools/OcrManager.kt
+4
-4
AppUtil.kt
app/src/main/java/com/duolebo/blyrobot/util/AppUtil.kt
+11
-10
No files found.
app/libs/log4j-1.2.17.jar
0 → 100644
View file @
7ea9e582
File added
app/src/main/java/com/duolebo/blyrobot/data/Task.kt
View file @
7ea9e582
...
...
@@ -128,6 +128,9 @@ class Task : Thread, IAppBaseCallback {
}
}
// 图片识别
imageOcrToNumber
()
// 上传图片
this
.
uploadImage
()
this
.
status
=
State
.
UPLOADING
...
...
@@ -139,7 +142,6 @@ class Task : Thread, IAppBaseCallback {
// 退出应用
AdbUtil
.
stopApp
(
this
.
apkInfo
.
packageName
)
imageOcrToNumber
();
// 上报数据,上传图片在后台进行
report
()
}
...
...
@@ -271,12 +273,16 @@ class Task : Thread, IAppBaseCallback {
var
time
=
imageDateFormat
.
format
(
Date
())
val
absName
=
this
.
taskPath
+
"/${this.apkInfo.packageName}_${channelIndex}_$time"
screenShot
(
absName
)
AppUtil
.
cropImage
(
"$absName.png"
)
screenImages
.
add
(
"$absName.jpg"
)
// 删除png图片
val
pngFile
=
File
(
"$absName.png"
)
pngFile
.
delete
()
AdbUtil
.
sendMultiKey
(
this
.
apkInfo
.
menuKeyEvent
)
time
=
imageDateFormat
.
format
(
Date
())
val
absOkName
=
this
.
taskPath
+
"/${this.apkInfo.packageName}_${channelIndex}_${time}_ok"
screenShot
(
absOkName
)
screenShot
(
absOkName
,
true
)
screenImages
.
add
(
"$absOkName.jpg"
)
// 对于一些epg弹出时间过长的应用,模拟点击一次返回键,比如电视家3.0
...
...
@@ -407,7 +413,7 @@ class Task : Thread, IAppBaseCallback {
}
// 截图处理,转成jpg
private
fun
screenShot
(
absName
:
String
)
{
private
fun
screenShot
(
absName
:
String
,
deletePng
:
Boolean
=
false
)
{
val
pngPath
=
"$absName.png"
val
jpgPath
=
pngPath
.
replace
(
".png"
,
".jpg"
)
AdbUtil
.
screenShot
(
pngPath
)
...
...
@@ -415,6 +421,7 @@ class Task : Thread, IAppBaseCallback {
val
pngFile
=
File
(
pngPath
)
if
(
pngFile
.
exists
())
{
AppUtil
.
pngToJpg
(
pngPath
,
jpgPath
)
if
(
deletePng
)
pngFile
.
delete
()
}
else
{
...
...
@@ -437,10 +444,15 @@ class Task : Thread, IAppBaseCallback {
for
(
i
in
0
..
channelArr
.
length
())
{
try
{
val
channelJson
=
channelArr
.
optJSONObject
(
i
)
va
l
imagePath
=
this
.
taskPath
+
"/"
+
channelJson
.
optString
(
"channelImage"
)
val
newImagePath
=
AppUtil
.
cropImage
(
imagePath
)
val
phoneNumber
=
OcrManager
.
instance
.
imageOcr
(
newI
magePath
)
va
r
imagePath
=
this
.
taskPath
+
"/"
+
channelJson
.
optString
(
"channelImage"
)
imagePath
=
imagePath
.
replace
(
".jpg"
,
"_ocr.jpg"
)
val
phoneNumber
=
OcrManager
.
instance
.
imageOcr
(
i
magePath
)
channelJson
.
putOpt
(
"phoneNumber"
,
phoneNumber
)
// 识别之后删除图片文件
val
imageFile
=
File
(
imagePath
)
imageFile
.
delete
()
}
catch
(
e
:
java
.
lang
.
Exception
)
{
e
.
printStackTrace
()
}
...
...
app/src/main/java/com/duolebo/blyrobot/tools/OcrManager.kt
View file @
7ea9e582
...
...
@@ -3,6 +3,7 @@ package com.duolebo.blyrobot.tools
import
android.annotation.SuppressLint
import
android.content.Context
import
android.text.TextUtils
import
android.util.Log
import
com.baidu.aip.ocr.AipOcr
import
java.io.File
...
...
@@ -34,8 +35,8 @@ class OcrManager {
// 初始化百度ocr调用
private
fun
initOcr
()
{
this
.
aipOcr
=
AipOcr
(
APP_ID
,
API_KEY
,
SECRET_KEY
)
aipOcr
.
setConnectionTimeoutInMillis
(
CONN_TIMEOUT
)
;
aipOcr
.
setSocketTimeoutInMillis
(
SOCKET_TIMEOUT
)
;
aipOcr
.
setConnectionTimeoutInMillis
(
CONN_TIMEOUT
)
aipOcr
.
setSocketTimeoutInMillis
(
SOCKET_TIMEOUT
)
}
fun
imageOcr
(
filePath
:
String
)
:
String
{
...
...
@@ -55,8 +56,7 @@ class OcrManager {
res
=
getOcrWords
(
result
)
}
val
imageFile
=
File
(
filePath
)
imageFile
.
delete
()
Log
.
i
(
TAG
,
"imageOrc: $res"
)
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
...
...
app/src/main/java/com/duolebo/blyrobot/util/AppUtil.kt
View file @
7ea9e582
...
...
@@ -96,30 +96,31 @@ object AppUtil {
}
}
fun
cropImage
(
imagePath
:
String
)
:
String
{
fun
cropImage
(
imagePath
:
String
){
val
bitmap
=
BitmapFactory
.
decodeFile
(
imagePath
)
val
cropBitmap
=
Bitmap
.
createBitmap
(
bitmap
,
0
,
905
,
1024
,
100
)
try
{
val
height
=
bitmap
.
height
val
cropBitmap
=
Bitmap
.
createBitmap
(
bitmap
,
0
,
height
-
100
,
1024
,
100
)
val
index
=
imagePath
.
lastIndexOf
(
'.'
)
val
partName
=
imagePath
.
substring
(
0
,
index
)
val
newPath
=
partName
+
"_ocr.jpg"
val
file
=
File
(
newPath
)
try
{
val
fos
=
FileOutputStream
(
file
)
BufferedOutputStream
(
fos
).
use
{
bos
->
if
(
cropBitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
10
0
,
bos
))
{
if
(
cropBitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
8
0
,
bos
))
{
bos
.
flush
()
}
bos
.
close
()
}
fos
.
close
()
cropBitmap
?.
recycle
()
}
catch
(
e
:
IOException
)
{
e
.
printStackTrace
()
}
finally
{
bitmap
!!
.
recycle
()
cropBitmap
!!
.
recycle
()
}
return
newPath
}
fun
readFromLocal
(
file
:
File
):
String
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment