OpenCV C++ on Android fails to decode QR which Opencv python does

I’ve generated a QR code and want to decode it by Opencv Android SDK 4.6.0.

The QR data is just a JSON string, generated by JS: {"url":"rdp://","mX":480,"mY":410,"mIn":true,"o":50,"w":2250,"h":1349,"s":300,"id":"ef4ac969"}

enter image description here

When I try to decode it by python (same CV version 4.6.0) everything works well:

def read_qr_code(filename):
        img = cv2.imread(filename)
        detect = cv2.QRCodeDetector()
        value, points, straight_qrcode = detect.detectAndDecode(img)
        return value
        print("Error loading image")

print("cv version:" + cv2.__version__)
value = read_qr_code("C:\qr\screenshot.jpg")
print("QR value:" + value)

cv version:4.6.0 QR
value: {“url”:“rdp://”,“mX”:480,“mY”:410,“mIn”:true,“o”:50,“w”:2250,“h”:1349,“s”:300,“id”:“ef4ac969”}

When I try to convert the same QR using OpenCv Android SDK, it’s not detected:

int read_qr(string filename)
    string image_path = filename;

    Mat getImage = imread(image_path);
        cout << "Could not read the image: " << image_path << endl;
        return -1;

    QRCodeDetector qrDet = QRCodeDetector();

    Mat points, rectImage;
    std::string data = qrDet.detectAndDecode(getImage, points, rectImage);
    if (data.length() > 0)
        cout << "Data after decoding: " << data << endl;
        cout << "QR Code not detected" << endl;
        return -1;

    return 0;

QR Code not detected

I didn’t find any information about the problem, and it doesn’t seem like there should be a difference between the python and c++ implementations

When I change the values in the Json a bit, it seems that sometimes it works. I didn’t find a certain pattern like a length or specific character, but when I change the QR sometimes it works.


1 Like

Is it a problem to ask in both communities?

declaring crossposts is important. if you don’t do that, people waste time investigating something that was already solved, or suggest approaches (again) that were already discussed. do you see?

I see, thanks!
Anyway nobody responded yet.

בתאריך יום ג׳, 8 בנוב׳ 2022 ב-23:28 מאת Christoph Rackwitz via OpenCV <>: