Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

QRCodeDetector in Android cause ANR(no response)

opencv android sdk 4.1.0

android api 28

I am testing QRCodeDetector, but something strange happens.

When QRCode Activity is turned on, the camera is normally turned on. If I don't shoot QRCode, I can return normally when I press the back button.

However, if I take the QRCode and it is detected normally, after pressing the back button, it seems to enter the ANR state. The touch of the screen is invalid, and the back button has no effect.

I have detected the backpressed method and did not trigger.

Does anyone have the same situation?

How can I solve this?

Here is my detection program:

      public class QrcodeDec implements IDetector {

private QRCodeDetector dec;
private AiResult aiResult;
public QrcodeDec(){
    init();
}





@Override
public void init() {
    dec=new QRCodeDetector();
    aiResult=new AiResult();
}

@Override
public String predict(Mat imageMat) {
    aiResult.setRawImageMat(imageMat);


    Mat points=new Mat();
    Mat straight_qrcode=new Mat();

    String result=dec.detectAndDecode(imageMat,points,straight_qrcode);

    if(result.equalsIgnoreCase("")){

    }else {
        display(imageMat,points);
    }

    return result;
}

ToneGenerator toneGen1 ;
private void display(Mat img, Mat points) {
    if (toneGen1 == null) {
        toneGen1 = new ToneGenerator(AudioManager.STREAM_MUSIC, 100);
    }
    toneGen1.startTone(ToneGenerator.TONE_CDMA_ABBR_ALERT, 150);
    int n = points.rows();
    for (int i = 0; i < n; i++) {
        double[] value = points.get(i, 0);
        double[] value1 = points.get((i + 1) % n, 0);
        Imgproc.line(img, new Point(value[0], value[1]), new Point(value1[0], value1[1]), new Scalar(255, 0, 0), 3);
    }
}


@Override
public List<Mat> getDigits() {
    return null;
}
@Override
public void close(){
    toneGen1.release();
}

}