简体   繁体   English

Android文字识别-限制文字识别器

[英]Android text recognition - Throttling the text recognizer

I'm testing the android vision text recognizer, and in real-time use, the docs suggest I "Throttle calls to the text recognizer. If a new video frame becomes available while the text recognizer is running, drop the frame." 我正在测试android vision文本识别器,并且在实时使用中, 文档建议我“对文本识别器进行节流调用。如果在文本识别器运行时有新的视频帧可用,请将其放下。”

In the sample ocr-reader app, which shares the CameraSource and OcrDetectorProcessor with the ML Kit sample app, I'm trying to figure out precisely how this is accomplished. 在与ML Kit示例应用程序共享CameraSourceOcrDetectorProcessor的示例ocr-reader应用程序中,我试图精确地确定这是如何实现的。 Can someone point me in the right direction? 有人可以指出我正确的方向吗? I'm lookng at the CameraPreviewCallback and FrameProcessingRunnable classes, but no progress yet. 我在看CameraPreviewCallbackFrameProcessingRunnable类,但是还没有进展。 Thanks! 谢谢!

I had the exact same question, but I managed to do it like this: it is quite "manual", the idea is to have a flag before passing the processImage to your detector. 我有完全相同的问题,但我设法做到这一点:这非常“手动”,其想法是在将processImage传递到检测器之前先有一个标志。


private var isProcessing = AtomicBoolean(false)

private fun process(image: FirebaseVisionImage) {
        isProcessing.set(true)
        detector.processImage(image)
            .addOnSuccessListener { texts ->
                processTextRecognitionResult(texts)
                isProcessing.set(false)
            }

            .addOnFailureListener {
                println("Detection failed with $it")
            }
    }

So basically 所以基本上

override fun analyze(imageProxy: ImageProxy?, degrees: Int) {
        imageProxy?.image?.let { image ->
            if(!isProcessing.get()) {
               process(image)
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM