6.6.0 - 内置模块重写; 新增部分模块及方法; 修复高版本安卓系统兼容问题; 优化文件管理器及打包功能体验
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.benjaminwan.ocrlibrary
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.AssetManager
|
||||
import android.graphics.Bitmap
|
||||
|
||||
class OcrEngine(context: Context) {
|
||||
companion object {
|
||||
const val numThread: Int = 4
|
||||
}
|
||||
|
||||
init {
|
||||
System.loadLibrary("RapidOcr")
|
||||
val ret = init(
|
||||
context.assets, numThread,
|
||||
"models/ch_PP-OCRv3_det_infer.onnx",
|
||||
"models/ch_ppocr_mobile_v2.0_cls_infer.onnx",
|
||||
"models/ch_PP-OCRv3_rec_infer.onnx",
|
||||
"models/ppocr_keys_v1.txt",
|
||||
)
|
||||
if (!ret) throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
var padding: Int = 50
|
||||
var boxScoreThresh: Float = 0.5f
|
||||
var boxThresh: Float = 0.3f
|
||||
var unClipRatio: Float = 1.6f
|
||||
var doAngle: Boolean = true
|
||||
var mostAngle: Boolean = true
|
||||
|
||||
fun detect(input: Bitmap, output: Bitmap, maxSideLen: Int) =
|
||||
detect(
|
||||
input, output, padding, maxSideLen,
|
||||
boxScoreThresh, boxThresh,
|
||||
unClipRatio, doAngle, mostAngle
|
||||
)
|
||||
|
||||
external fun init(
|
||||
assetManager: AssetManager,
|
||||
numThread: Int, detName: String,
|
||||
clsName: String, recName: String, keysName: String
|
||||
): Boolean
|
||||
|
||||
external fun detect(
|
||||
input: Bitmap, output: Bitmap, padding: Int, maxSideLen: Int,
|
||||
boxScoreThresh: Float, boxThresh: Float,
|
||||
unClipRatio: Float, doAngle: Boolean, mostAngle: Boolean
|
||||
): OcrResult
|
||||
|
||||
external fun benchmark(input: Bitmap, loop: Int): Double
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.benjaminwan.ocrlibrary
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
open class OcrOutput
|
||||
|
||||
object OcrStop : OcrOutput()
|
||||
object OcrFailed : OcrOutput()
|
||||
|
||||
@Parcelize
|
||||
data class OcrResult(
|
||||
val dbNetTime: Double,
|
||||
val textBlocks: ArrayList<TextBlock>,
|
||||
var boxImg: Bitmap,
|
||||
var detectTime: Double,
|
||||
var strRes: String
|
||||
) : Parcelable, OcrOutput()
|
||||
|
||||
@Parcelize
|
||||
data class Point(var x: Int, var y: Int) : Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class TextBlock(
|
||||
val boxPoint: ArrayList<Point>, var boxScore: Float,
|
||||
val angleIndex: Int, val angleScore: Float, val angleTime: Double,
|
||||
val text: String, val charScores: FloatArray, val crnnTime: Double,
|
||||
val blockTime: Double
|
||||
) : Parcelable {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as TextBlock
|
||||
|
||||
if (boxPoint != other.boxPoint) return false
|
||||
if (boxScore != other.boxScore) return false
|
||||
if (angleIndex != other.angleIndex) return false
|
||||
if (angleScore != other.angleScore) return false
|
||||
if (angleTime != other.angleTime) return false
|
||||
if (text != other.text) return false
|
||||
if (!charScores.contentEquals(other.charScores)) return false
|
||||
if (crnnTime != other.crnnTime) return false
|
||||
if (blockTime != other.blockTime) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = boxPoint.hashCode()
|
||||
result = 31 * result + boxScore.hashCode()
|
||||
result = 31 * result + angleIndex
|
||||
result = 31 * result + angleScore.hashCode()
|
||||
result = 31 * result + angleTime.hashCode()
|
||||
result = 31 * result + text.hashCode()
|
||||
result = 31 * result + charScores.contentHashCode()
|
||||
result = 31 * result + crnnTime.hashCode()
|
||||
result = 31 * result + blockTime.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user