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://52.170.146.204","mX":480,"mY":410,"mIn":true,"o":50,"w":2250,"h":1349,"s":300,"id":"ef4ac969"}
When I try to decode it by python (same CV version 4.6.0) everything works well:
def read_qr_code(filename):
try:
img = cv2.imread(filename)
detect = cv2.QRCodeDetector()
value, points, straight_qrcode = detect.detectAndDecode(img)
return value
except:
print("Error loading image")
return
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://52.170.146.204”,“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);
if(getImage.empty())
{
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;
}
else
{
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.