Commit 812c2d5b authored by liuyang's avatar liuyang

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

#BYLSERVER-1438
parent 7ea9e582
...@@ -13,7 +13,7 @@ android { ...@@ -13,7 +13,7 @@ android {
minSdkVersion 15 minSdkVersion 15
targetSdkVersion 22 targetSdkVersion 22
versionCode 20 versionCode 20
versionName "1.5.4" versionName "1.6.1"
} }
signingConfigs { signingConfigs {
......
...@@ -5,7 +5,7 @@ import android.content.Context ...@@ -5,7 +5,7 @@ import android.content.Context
import android.text.TextUtils import android.text.TextUtils
import android.util.Log import android.util.Log
import com.baidu.aip.ocr.AipOcr import com.baidu.aip.ocr.AipOcr
import java.io.File import java.util.regex.Pattern
class OcrManager { class OcrManager {
...@@ -51,7 +51,7 @@ class OcrManager { ...@@ -51,7 +51,7 @@ class OcrManager {
res = getOcrWords(result) res = getOcrWords(result)
// 如果无法识别,调用高精度识别,每天500次额度 // 如果无法识别,调用高精度识别,每天500次额度
if (!TextUtils.isDigitsOnly(res)) { if (TextUtils.isEmpty(res)) {
result = aipOcr.basicAccurateGeneral(filePath, options) result = aipOcr.basicAccurateGeneral(filePath, options)
res = getOcrWords(result) res = getOcrWords(result)
} }
...@@ -69,12 +69,34 @@ class OcrManager { ...@@ -69,12 +69,34 @@ class OcrManager {
val wordsResult = result.getJSONArray("words_result") val wordsResult = result.getJSONArray("words_result")
val num = result.getInt("words_result_num") val num = result.getInt("words_result_num")
if (wordsResult != null && num > 0) { if (wordsResult != null && num > 0) {
val wordsObject = wordsResult.getJSONObject(0) val len = wordsResult.length()
words = wordsObject.getString("words") for ( i in 0..len) {
words = words.replace("-", "") 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 { 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