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

QRCodeDetector on android does not decode #24318

Closed
4 tasks done
EddyTheCo opened this issue Sep 25, 2023 · 5 comments · Fixed by #24299
Closed
4 tasks done

QRCodeDetector on android does not decode #24318

EddyTheCo opened this issue Sep 25, 2023 · 5 comments · Fixed by #24299

Comments

@EddyTheCo
Copy link

System Information

OpenCV version: 4.8.0
Android 11
Android NDK

Detailed description

I am using precompiled libraries of OpenCV taken from these releases.

The precompiled libraries are used by my library using this CMakeLists.txt

This library works well in wasm, and desktop(only tested in linux). But when using Android, I can check that the QRCodeDetector detects the QRCODE but never decodes it.
Also when using auto str=detectAndDecodeCurved(greyImg,corners); corners becomes a 1x4 matrix, what are those numbers?
It is not clear to me what the documentation means with 'vertices of the found QR code quadrangle'. In what unit, what is the reference point? How can you express four vertices in a 2D plane with 4 numbers?

I see that when pointing the camera to a QRCODE corners becomes a 1x4 matrix, so it is detecting something.

Steps to reproduce

std::string MyQRCodeDetector::decode_grey(unsigned char* img,int rows ,int cols)
{
    cv::Mat greyImg = cv::Mat(rows,cols, CV_8UC1, img);

    cv::Mat corners;
    auto str=detectAndDecodeCurved(greyImg,corners);

    qDebug()<<"cols:"<<corners.cols;
    qDebug()<<"rows:"<<corners.rows;
    qDebug()<<"depth:"<<corners.depth();

    for(int i = 0 ; i < corners.rows ; i++)
    {
        for(int j = 0 ; j < corners.cols ; j++)
        {
            qDebug()<<corners.at<float>(i,j);

        }
    }
    if(corners.rows&&corners.cols)
    {
        cv::line(greyImg, cv::Point2i(corners.at<float>(0,0),corners.at<float>(0,1)), cv::Point2i(corners.at<float>(0,2),corners.at<float>(0,1)), cv::Scalar(100,200,155), 11);
        cv::line(greyImg, cv::Point2i(corners.at<float>(0,2),corners.at<float>(0,1)),cv::Point2i(corners.at<float>(0,2),corners.at<float>(0,3)), cv::Scalar(30,100,0), 8);
        cv::line(greyImg, cv::Point2i(corners.at<float>(0,0),corners.at<float>(0,1)), cv::Point2i(corners.at<float>(0,0),corners.at<float>(0,3)), cv::Scalar(150,4,255), 5);
        cv::line(greyImg, cv::Point2i(corners.at<float>(0,0),corners.at<float>(0,3)),cv::Point2i(corners.at<float>(0,2),corners.at<float>(0,3)), cv::Scalar(75,75,75), 2);
    }
    qDebug()<<"STTTTRRR:"<<str;
    return str;
}

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
@EddyTheCo EddyTheCo added the bug label Sep 25, 2023
@asmorkalov
Copy link
Contributor

please attach test image.

@EddyTheCo
Copy link
Author

EddyTheCo commented Sep 25, 2023

I am using the cellphone camera I have tried with many qr codes(for example the first one from Wikipedia).
There is no easy way to print the greyImg Mat on the Android debugger. And I think imshow(),imwrite() will not work on Android so easy.

I can see the resulting image after doing cv::line(greyImg,...
It is a clear image containing a QRCODE with segments(created with cv::line ), one on top of each other from the top-left to the top-right corner of the QRCODE. If there is no QRCODE on the picture no segment is shown.
The segments on top of each other are shown also in Linux desktop with a webcam, but there the QRCODE is decoded.

@EddyTheCo
Copy link
Author

EddyTheCo commented Sep 26, 2023

I was using OpenCV 4.5.5 on the desktop and 4.8.0 on Android. When using OpenCV 4.8.0 on the Desktop the app prints Library QUIRC is not linked. No decoding is performed. Take it to the OpenCV repository. This is not printed on the Android debugger(as expected from the debugger).
So I am changing -DWITH_QUIRC=OFF to -DWITH_QUIRC=ON when building OpenCV. Let's see if that solves the issue.

@AleksandrPanov
Copy link
Contributor

AleksandrPanov commented Oct 2, 2023

"Also when using auto str=detectAndDecodeCurved(greyImg,corners); corners becomes a 1x4 matrix, what are those numbers?
It is not clear to me what the documentation means with 'vertices of the found QR code quadrangle'. In what unit, what is the reference point? How can you express four vertices in a 2D plane with 4 numbers?
I see that when pointing the camera to a QRCODE corners becomes a 1x4 matrix, so it is detecting something."

@EddyTheCo, cv::Mat uses 1x4 matrix with two channels in this case. You can just cout<<corners to check this.
You can use this code to get value of i corner from 1x4 Mat with 2 channels: Point2f corner_i = corners.at<Point2f>(0,i);
Also you can just use std::vector<Point> corners, detectAndDecodeCurved return std::vector in this case.

Uses channels() method to get num channels.

How is the image matrix stored in memory?

@AleksandrPanov
Copy link
Contributor

@EddyTheCo, thank you, I think that we need to update docs for detectAndDecode()

asmorkalov pushed a commit that referenced this issue Nov 24, 2023
In-house QR codes decoding #24299

### Pull Request Readiness Checklist

QR codes decoding pipeline without 3rdparty dependency (Quirc library). Implemented according to standard https://github.com/yansikeim/QR-Code/blob/master/ISO%20IEC%2018004%202015%20Standard.pdf

**Merge with extra**: opencv/opencv_extra#1124

resolves #24225
resolves #17290
resolves #24318 #24346

Resources:
* https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders
* https://en.wikipedia.org/wiki/Berlekamp%E2%80%93Massey_algorithm

```
Geometric mean (ms)

                                   Name of Test                                      quirc   new2      new2   
                                                                                                        vs    
                                                                                                      quirc   
                                                                                                    (x-factor)
decode::Perf_Objdetect_Not_QRCode::("chessboard", 640x480)                           9.151   9.157     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 1280x720)                         21.609  21.609     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 1920x1080)                        42.088  41.924     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 3840x2160)                        169.737 169.050    1.00   
decode::Perf_Objdetect_Not_QRCode::("random", 640x480)                               8.552   8.611     0.99   
decode::Perf_Objdetect_Not_QRCode::("random", 1280x720)                             21.264  21.581     0.99   
decode::Perf_Objdetect_Not_QRCode::("random", 1920x1080)                            42.415  43.468     0.98   
decode::Perf_Objdetect_Not_QRCode::("random", 3840x2160)                            175.003 174.294    1.00   
decode::Perf_Objdetect_Not_QRCode::("zero", 640x480)                                 8.528   8.421     1.01   
decode::Perf_Objdetect_Not_QRCode::("zero", 1280x720)                               21.548  21.209     1.02   
decode::Perf_Objdetect_Not_QRCode::("zero", 1920x1080)                              42.581  42.529     1.00   
decode::Perf_Objdetect_Not_QRCode::("zero", 3840x2160)                              176.231 174.410    1.01   
decode::Perf_Objdetect_QRCode::"kanji.jpg"                                           6.105   6.072     1.01   
decode::Perf_Objdetect_QRCode::"link_github_ocv.jpg"                                 6.069   6.076     1.00   
decode::Perf_Objdetect_QRCode::"link_ocv.jpg"                                        6.143   6.240     0.98   
decode::Perf_Objdetect_QRCode::"link_wiki_cv.jpg"                                    6.369   6.420     0.99   
decode::Perf_Objdetect_QRCode::"russian.jpg"                                         6.558   6.549     1.00   
decode::Perf_Objdetect_QRCode::"version_1_down.jpg"                                  5.634   5.621     1.00   
decode::Perf_Objdetect_QRCode::"version_1_left.jpg"                                  5.560   5.609     0.99   
decode::Perf_Objdetect_QRCode::"version_1_right.jpg"                                 5.539   5.631     0.98   
decode::Perf_Objdetect_QRCode::"version_1_top.jpg"                                   5.622   5.566     1.01   
decode::Perf_Objdetect_QRCode::"version_1_up.jpg"                                    5.569   5.534     1.01   
decode::Perf_Objdetect_QRCode::"version_5_down.jpg"                                  6.514   6.436     1.01   
decode::Perf_Objdetect_QRCode::"version_5_left.jpg"                                  6.668   6.479     1.03   
decode::Perf_Objdetect_QRCode::"version_5_top.jpg"                                   6.481   6.484     1.00   
decode::Perf_Objdetect_QRCode::"version_5_up.jpg"                                    7.011   6.513     1.08   
decodeMulti::Perf_Objdetect_QRCode_Multi::("2_qrcodes.png", "aruco_based")          14.885  15.089     0.99   
decodeMulti::Perf_Objdetect_QRCode_Multi::("2_qrcodes.png", "contours_based")       14.896  14.906     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_close_qrcodes.png", "aruco_based")     6.661   6.663     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_close_qrcodes.png", "contours_based")  6.614   6.592     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_qrcodes.png", "aruco_based")          14.814  14.592     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_qrcodes.png", "contours_based")       15.245  15.135     1.01   
decodeMulti::Perf_Objdetect_QRCode_Multi::("4_qrcodes.png", "aruco_based")          10.923  10.881     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("4_qrcodes.png", "contours_based")       10.680  10.128     1.05   
decodeMulti::Perf_Objdetect_QRCode_Multi::("5_qrcodes.png", "contours_based")       11.788  11.576     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("6_qrcodes.png", "aruco_based")          25.887  25.979     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("6_qrcodes.png", "contours_based")       26.183  25.627     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("7_qrcodes.png", "aruco_based")          32.786  32.253     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("7_qrcodes.png", "contours_based")       24.290  24.435     0.99   
decodeMulti::Perf_Objdetect_QRCode_Multi::("8_close_qrcodes.png", "aruco_based")    89.696  89.247     1.01   
decodeMulti::Perf_Objdetect_QRCode_Multi::("8_close_qrcodes.png", "contours_based") 89.872  89.600     1.00
```
IskXCr pushed a commit to Haosonn/opencv that referenced this issue Dec 20, 2023
In-house QR codes decoding opencv#24299

### Pull Request Readiness Checklist

QR codes decoding pipeline without 3rdparty dependency (Quirc library). Implemented according to standard https://github.com/yansikeim/QR-Code/blob/master/ISO%20IEC%2018004%202015%20Standard.pdf

**Merge with extra**: opencv/opencv_extra#1124

resolves opencv#24225
resolves opencv#17290
resolves opencv#24318 opencv#24346

Resources:
* https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders
* https://en.wikipedia.org/wiki/Berlekamp%E2%80%93Massey_algorithm

```
Geometric mean (ms)

                                   Name of Test                                      quirc   new2      new2   
                                                                                                        vs    
                                                                                                      quirc   
                                                                                                    (x-factor)
decode::Perf_Objdetect_Not_QRCode::("chessboard", 640x480)                           9.151   9.157     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 1280x720)                         21.609  21.609     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 1920x1080)                        42.088  41.924     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 3840x2160)                        169.737 169.050    1.00   
decode::Perf_Objdetect_Not_QRCode::("random", 640x480)                               8.552   8.611     0.99   
decode::Perf_Objdetect_Not_QRCode::("random", 1280x720)                             21.264  21.581     0.99   
decode::Perf_Objdetect_Not_QRCode::("random", 1920x1080)                            42.415  43.468     0.98   
decode::Perf_Objdetect_Not_QRCode::("random", 3840x2160)                            175.003 174.294    1.00   
decode::Perf_Objdetect_Not_QRCode::("zero", 640x480)                                 8.528   8.421     1.01   
decode::Perf_Objdetect_Not_QRCode::("zero", 1280x720)                               21.548  21.209     1.02   
decode::Perf_Objdetect_Not_QRCode::("zero", 1920x1080)                              42.581  42.529     1.00   
decode::Perf_Objdetect_Not_QRCode::("zero", 3840x2160)                              176.231 174.410    1.01   
decode::Perf_Objdetect_QRCode::"kanji.jpg"                                           6.105   6.072     1.01   
decode::Perf_Objdetect_QRCode::"link_github_ocv.jpg"                                 6.069   6.076     1.00   
decode::Perf_Objdetect_QRCode::"link_ocv.jpg"                                        6.143   6.240     0.98   
decode::Perf_Objdetect_QRCode::"link_wiki_cv.jpg"                                    6.369   6.420     0.99   
decode::Perf_Objdetect_QRCode::"russian.jpg"                                         6.558   6.549     1.00   
decode::Perf_Objdetect_QRCode::"version_1_down.jpg"                                  5.634   5.621     1.00   
decode::Perf_Objdetect_QRCode::"version_1_left.jpg"                                  5.560   5.609     0.99   
decode::Perf_Objdetect_QRCode::"version_1_right.jpg"                                 5.539   5.631     0.98   
decode::Perf_Objdetect_QRCode::"version_1_top.jpg"                                   5.622   5.566     1.01   
decode::Perf_Objdetect_QRCode::"version_1_up.jpg"                                    5.569   5.534     1.01   
decode::Perf_Objdetect_QRCode::"version_5_down.jpg"                                  6.514   6.436     1.01   
decode::Perf_Objdetect_QRCode::"version_5_left.jpg"                                  6.668   6.479     1.03   
decode::Perf_Objdetect_QRCode::"version_5_top.jpg"                                   6.481   6.484     1.00   
decode::Perf_Objdetect_QRCode::"version_5_up.jpg"                                    7.011   6.513     1.08   
decodeMulti::Perf_Objdetect_QRCode_Multi::("2_qrcodes.png", "aruco_based")          14.885  15.089     0.99   
decodeMulti::Perf_Objdetect_QRCode_Multi::("2_qrcodes.png", "contours_based")       14.896  14.906     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_close_qrcodes.png", "aruco_based")     6.661   6.663     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_close_qrcodes.png", "contours_based")  6.614   6.592     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_qrcodes.png", "aruco_based")          14.814  14.592     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_qrcodes.png", "contours_based")       15.245  15.135     1.01   
decodeMulti::Perf_Objdetect_QRCode_Multi::("4_qrcodes.png", "aruco_based")          10.923  10.881     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("4_qrcodes.png", "contours_based")       10.680  10.128     1.05   
decodeMulti::Perf_Objdetect_QRCode_Multi::("5_qrcodes.png", "contours_based")       11.788  11.576     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("6_qrcodes.png", "aruco_based")          25.887  25.979     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("6_qrcodes.png", "contours_based")       26.183  25.627     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("7_qrcodes.png", "aruco_based")          32.786  32.253     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("7_qrcodes.png", "contours_based")       24.290  24.435     0.99   
decodeMulti::Perf_Objdetect_QRCode_Multi::("8_close_qrcodes.png", "aruco_based")    89.696  89.247     1.01   
decodeMulti::Perf_Objdetect_QRCode_Multi::("8_close_qrcodes.png", "contours_based") 89.872  89.600     1.00
```
thewoz pushed a commit to thewoz/opencv that referenced this issue May 29, 2024
In-house QR codes decoding opencv#24299

### Pull Request Readiness Checklist

QR codes decoding pipeline without 3rdparty dependency (Quirc library). Implemented according to standard https://github.com/yansikeim/QR-Code/blob/master/ISO%20IEC%2018004%202015%20Standard.pdf

**Merge with extra**: opencv/opencv_extra#1124

resolves opencv#24225
resolves opencv#17290
resolves opencv#24318 opencv#24346

Resources:
* https://en.wikiversity.org/wiki/Reed%E2%80%93Solomon_codes_for_coders
* https://en.wikipedia.org/wiki/Berlekamp%E2%80%93Massey_algorithm

```
Geometric mean (ms)

                                   Name of Test                                      quirc   new2      new2   
                                                                                                        vs    
                                                                                                      quirc   
                                                                                                    (x-factor)
decode::Perf_Objdetect_Not_QRCode::("chessboard", 640x480)                           9.151   9.157     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 1280x720)                         21.609  21.609     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 1920x1080)                        42.088  41.924     1.00   
decode::Perf_Objdetect_Not_QRCode::("chessboard", 3840x2160)                        169.737 169.050    1.00   
decode::Perf_Objdetect_Not_QRCode::("random", 640x480)                               8.552   8.611     0.99   
decode::Perf_Objdetect_Not_QRCode::("random", 1280x720)                             21.264  21.581     0.99   
decode::Perf_Objdetect_Not_QRCode::("random", 1920x1080)                            42.415  43.468     0.98   
decode::Perf_Objdetect_Not_QRCode::("random", 3840x2160)                            175.003 174.294    1.00   
decode::Perf_Objdetect_Not_QRCode::("zero", 640x480)                                 8.528   8.421     1.01   
decode::Perf_Objdetect_Not_QRCode::("zero", 1280x720)                               21.548  21.209     1.02   
decode::Perf_Objdetect_Not_QRCode::("zero", 1920x1080)                              42.581  42.529     1.00   
decode::Perf_Objdetect_Not_QRCode::("zero", 3840x2160)                              176.231 174.410    1.01   
decode::Perf_Objdetect_QRCode::"kanji.jpg"                                           6.105   6.072     1.01   
decode::Perf_Objdetect_QRCode::"link_github_ocv.jpg"                                 6.069   6.076     1.00   
decode::Perf_Objdetect_QRCode::"link_ocv.jpg"                                        6.143   6.240     0.98   
decode::Perf_Objdetect_QRCode::"link_wiki_cv.jpg"                                    6.369   6.420     0.99   
decode::Perf_Objdetect_QRCode::"russian.jpg"                                         6.558   6.549     1.00   
decode::Perf_Objdetect_QRCode::"version_1_down.jpg"                                  5.634   5.621     1.00   
decode::Perf_Objdetect_QRCode::"version_1_left.jpg"                                  5.560   5.609     0.99   
decode::Perf_Objdetect_QRCode::"version_1_right.jpg"                                 5.539   5.631     0.98   
decode::Perf_Objdetect_QRCode::"version_1_top.jpg"                                   5.622   5.566     1.01   
decode::Perf_Objdetect_QRCode::"version_1_up.jpg"                                    5.569   5.534     1.01   
decode::Perf_Objdetect_QRCode::"version_5_down.jpg"                                  6.514   6.436     1.01   
decode::Perf_Objdetect_QRCode::"version_5_left.jpg"                                  6.668   6.479     1.03   
decode::Perf_Objdetect_QRCode::"version_5_top.jpg"                                   6.481   6.484     1.00   
decode::Perf_Objdetect_QRCode::"version_5_up.jpg"                                    7.011   6.513     1.08   
decodeMulti::Perf_Objdetect_QRCode_Multi::("2_qrcodes.png", "aruco_based")          14.885  15.089     0.99   
decodeMulti::Perf_Objdetect_QRCode_Multi::("2_qrcodes.png", "contours_based")       14.896  14.906     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_close_qrcodes.png", "aruco_based")     6.661   6.663     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_close_qrcodes.png", "contours_based")  6.614   6.592     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_qrcodes.png", "aruco_based")          14.814  14.592     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("3_qrcodes.png", "contours_based")       15.245  15.135     1.01   
decodeMulti::Perf_Objdetect_QRCode_Multi::("4_qrcodes.png", "aruco_based")          10.923  10.881     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("4_qrcodes.png", "contours_based")       10.680  10.128     1.05   
decodeMulti::Perf_Objdetect_QRCode_Multi::("5_qrcodes.png", "contours_based")       11.788  11.576     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("6_qrcodes.png", "aruco_based")          25.887  25.979     1.00   
decodeMulti::Perf_Objdetect_QRCode_Multi::("6_qrcodes.png", "contours_based")       26.183  25.627     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("7_qrcodes.png", "aruco_based")          32.786  32.253     1.02   
decodeMulti::Perf_Objdetect_QRCode_Multi::("7_qrcodes.png", "contours_based")       24.290  24.435     0.99   
decodeMulti::Perf_Objdetect_QRCode_Multi::("8_close_qrcodes.png", "aruco_based")    89.696  89.247     1.01   
decodeMulti::Perf_Objdetect_QRCode_Multi::("8_close_qrcodes.png", "contours_based") 89.872  89.600     1.00
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants