You need to sign in or sign up before continuing.
Commit 812c2d5b authored by liuyang's avatar liuyang

APK图片抓取识别及轮播流地址抓取, 优化识别结果提取

#BYLSERVER-1438
parent 7ea9e582
......@@ -13,7 +13,7 @@ android {
minSdkVersion 15
targetSdkVersion 22
versionCode 20
versionName "1.5.4"
versionName "1.6.1"
}
signingConfigs {
......
......@@ -5,7 +5,7 @@ import android.content.Context
import android.text.TextUtils
import android.util.Log
import com.baidu.aip.ocr.AipOcr
import java.io.File
import java.util.regex.Pattern
class OcrManager {
......@@ -51,7 +51,7 @@ class OcrManager {
res = getOcrWords(result)
// 如果无法识别,调用高精度识别,每天500次额度
if (!TextUtils.isDigitsOnly(res)) {
if (TextUtils.isEmpty(res)) {
result = aipOcr.basicAccurateGeneral(filePath, options)
res = getOcrWords(result)
}
......@@ -69,12 +69,34 @@ class OcrManager {
val wordsResult = result.getJSONArray("words_result")
val num = result.getInt("words_result_num")
if (wordsResult != null && num > 0) {
val wordsObject = wordsResult.getJSONObject(0)
words = wordsObject.getString("words")
words = words.replace("-", "")
val len = wordsResult.length()
for ( i in 0..len) {
val wordsObject = wordsResult.getJSONObject(i)
try {
val rawWords = wordsObject.getString("words")
// 提取数字
val regEx = "[^0-9]"
val p = Pattern.compile(regEx)
val m = p.matcher(rawWords)
val newWords = m.replaceAll("").trim()
if (newWords.length == 11) {
words = newWords
break
}
else if (words.isEmpty()) {
words = newWords
}
else if (newWords.length > words.length) {
words = newWords
}
} catch (e : java.lang.Exception) {
e.printStackTrace()
}
}
}
return words
return words
}
interface OcrListener {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment