Ask Your Question
0

QRCodeDetector in Android cause ANR(no response)

asked 2019-07-13 00:25:40 -0600

NickKao gravatar image

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();
}

}

edit retag flag offensive close merge delete

Comments

I am not in the normal way to implement CameraBridgeViewBase.CvCameraViewListener2 in the activity, then load opencv in onResume,

Instead, implement CameraBridgeViewBase.CvCameraViewListener2 in the View and load opencv. Although it can start normally, backonpressed() will cause an exception.

NickKao gravatar imageNickKao ( 2019-07-18 22:28:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-07-19 00:29:50 -0600

NickKao gravatar image

I have found a solution myself! Although I still don't know why. But at least for now!

Pay attention to the time to load opencv (onResume) and can not use runOnUiThread

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-07-13 00:25:40 -0600

Seen: 440 times

Last updated: Jul 19 '19