Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

问个奇葩问题,clone了你代码,然后我想在androidTest自动化里面调用paddle ocr识别图片信息,发现不行?但是我看日志有运行的 #39

Open
lycfr opened this issue Mar 22, 2024 · 5 comments

Comments

@lycfr
Copy link

lycfr commented Mar 22, 2024

代码目录结构这样子:
image

ExampleInstrumentedTest

@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
@lycfr
Copy link
Author

lycfr commented Mar 22, 2024

获取sdcard下的图片,app需要申请一下存储权限~

@equationl
Copy link
Owner

使用的是什么部署?paddle-lite ?

@lycfr
Copy link
Author

lycfr commented Mar 25, 2024

我直接git clone你的paddleocr4android项目。没有做其他操作,直接写了一个androidTest。是还有其他操作吗?

@equationl
Copy link
Owner

上一个 issue 回复你了,你确认一下用的什么部署方式

@lycfr
Copy link
Author

lycfr commented Mar 25, 2024

我使用的paddle-lite提供的nb文件,然后替换paddleocr4android里面PaddleOCR4Android自带的nb文件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants