You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
val TAG = "cfr"
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
// assertEquals("com.equationl.paddleocr4android", appContext.packageName)
Log.i(TAG, "useAppContext: 测试成功")
val ocr = OCR(appContext)
val config = OcrConfig()
config.labelPath = null
config.modelPath = "models/ch_PP-OCRv2" // 不使用 "/" 开头的路径表示安装包中 assets 目录下的文件,例如当前表示 assets/models/ocr_v2_for_cpu
//config.modelPath = "/sdcard/Android/data/com.equationl.paddleocr4android.app/files/models" // 使用 "/" 表示手机储存路径,测试时请将下载的三个模型放置于该目录下
config.clsModelFilename = "cls.nb" // cls 模型文件名
config.detModelFilename = "det_db.nb" // det 模型文件名
config.recModelFilename = "rec_crnn.nb" // rec 模型文件名
// 运行全部模型
// 请根据需要配置,三项全开识别率最高;如果只开识别几乎无法正确识别,至少需要搭配检测或分类其中之一
// 也可单独运行 检测模型 获取文本位置
config.isRunDet = true
config.isRunCls = true
config.isRunRec = true
// 使用所有核心运行
config.cpuPowerMode = CpuPowerMode.LITE_POWER_FULL
// 绘制文本位置
config.isDrwwTextPositionBox = true
// 1.同步初始化
ocr.initModelSync(config).fold(
{
if (it) {
Log.i(TAG, "onCreate: init success")
}
},
{
it.printStackTrace()
}
)
val file = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)
val imageFile = File(file,"/Camera/test4.png")
Log.i(TAG, "识别图片信息:" + imageFile.absolutePath)
val bitmap = BitmapFactory.decodeFile(imageFile.absolutePath)
ocr.getPredictor().setInputImage(bitmap)
ocr.runModel()
// ocr.runSync(bitmap)
Log.i(TAG, "识别信息:" + ocr.getPredictor().wordLabels + ",耗时:" + ocr.getPredictor().inferenceTime())
}
}
我运行后,看日志模型那些都是加载成功的,但是输出word都是xxx
2024-03-22 17:14:12.244 17380-17411 Predictor com.equationl.paddleocr4android.app E Word index is not in label list:1616
2024-03-22 17:14:12.244 17380-17411 Predictor com.equationl.paddleocr4android.app E Word index is not in label list:4105
2024-03-22 17:14:12.244 17380-17411 Predictor com.equationl.paddleocr4android.app I [stat] Inference Time: 401.0 ;Box Size 5
2024-03-22 17:14:12.244 17380-17411 Predictor com.equationl.paddleocr4android.app I ×××××××××××××××××
2024-03-22 17:14:12.244 17380-17411 Predictor com.equationl.paddleocr4android.app I ××××××××××
2024-03-22 17:14:12.244 17380-17411 Predictor com.equationl.paddleocr4android.app I ×××××××××××××××
2024-03-22 17:14:12.244 17380-17411 Predictor com.equationl.paddleocr4android.app I ××××××××××××××××××××
2024-03-22 17:14:12.244 17380-17411 Predictor com.equationl.paddleocr4android.app I ××××××××××××××
2024-03-22 17:14:12.244 17380-17411 OpenGLRenderer com.equationl.paddleocr4android.app D Skia GL Pipeline
2024-03-22 17:14:12.245 17380-17411 cfr com.equationl.paddleocr4android.app I 识别信息:[],耗时:401.0
The text was updated successfully, but these errors were encountered:
代码目录结构这样子:
ExampleInstrumentedTest
我运行后,看日志模型那些都是加载成功的,但是输出word都是xxx
The text was updated successfully, but these errors were encountered: