khanamiryan / php-qrcode-detector-decoder

This is a PHP library to detect and decode QR-codes. This is first and only QR code reader that works without extensions.
Apache License 2.0
1.37k stars 323 forks source link

Wrong result #15

Open powtac opened 8 years ago

powtac commented 8 years ago

This file can not be decoded with QrReader! it just returns (bool)false. But the text encoded in the QR Code is w_537244_40.

$QrReader = new QrReader('wrong.png');
echo $QrReader->text();

wrong

The correct result can be proved with the online Zxing.org encoder here. It returns:

Raw text              w_537244_40
Raw bytes             40 27 75 f1 01 a1 93 d1   00 d7 cd 0c 00 ec 11 ec
Barcode format        QR_CODE
Parsed Result Type    TEXT
Parsed Result         w_537244_40
powtac commented 8 years ago

Another image that can not be decoded. Should contains w_537241_108 but returns (bool)false. :-(

wrong2

jlemale commented 8 years ago

Unfortunately you're right. How did you generate those qr codes ? (I'm not a developer on this project but just curious)

powtac commented 8 years ago

Those images where created by a PHP library, TCPDF

jlemale commented 8 years ago

Just read http://www.tcpdf.org/doc/code/classTCPDF2DBarcode.html Which type did you use ? QRCODE : QRcode Low error correction QRCODE,L : QRcode Low error correction QRCODE,M : QRcode Medium error correction QRCODE,Q : QRcode Better error correction QRCODE,H : QR-CODE Best error correction

If you use a different one, is QrReader working ?

powtac commented 8 years ago

Default settings

powtac commented 8 years ago

It is not the creation lib that fails. The generated codes can be read via common smartphone readers!

jlemale commented 8 years ago

Yeah I just wanted to check if the error correction could have been an issue for this reader. But I guess no..

powtac commented 8 years ago

What I discovered as well: when running the creation of the QR codes a different code for the same content is created. It seems like there are around 3 different versions of QR codes for the same text. I did a quick search and found a random part in the QR lib, so this is ok. BUT only one of the three QR codes fail with the detector!

powtac commented 8 years ago

Similar to #9, #12 and #13

jamiedunns commented 8 years ago

i have a similar issue with the attached, i have created many QR codes with the same structure but different event id, but for some reason {"Event ID":"219619"} as the content just doesnt work, any ideas?

it was created using phpqrcode QRcode::png({"Event ID":"219619"},false,QR_ECLEVEL_L,35);

219619 5

qhxin commented 7 years ago

i have the same issue, so ,how did u solve it?😂

powtac commented 7 years ago

I have not solved it.

qhxin commented 7 years ago

@powtac

this is my code and it works well , but it still can't recognize #9.

https://github.com/qhxin/qhQrCodeReader

jlemale commented 7 years ago

I don't know about you guys but I had to recognise Qr Codes that I generated. So after a qrcode generation I checked if I could read it with this library before printing it otherwise I would create a new one. But I guess most of you don't create the qr codes.. GL..

powtac commented 7 years ago

Actually I made the same kind of workaround.

Am 27.12.2016 um 16:49 schrieb jlemale notifications@github.com:

I don't know about you guys but I had to recognise Qr Codes that I generated. So after a qrcode generation I checked if I could read it with this library before printing it otherwise I would create a new one. But I guess most of you don't create the qr codes.. GL..

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

qhxin commented 7 years ago

i don't create the qr codes, actually it's a part of my spider , so, i have to try to stretch it to different sizes to identify, that's too bad, but there's no other way.😂

githubjeka commented 7 years ago

To fix my issue like as your issue, I used imagecopyresampled For example you can see my code:

$width = imagesx($imageResource);
$height = imagesy($imageResource);

for ($zoom = 100; $zoom >= 10; $zoom -= 10) {
    $new_width = $width * $zoom / 100;
    $new_height = $height * $zoom / 100;
    $zoomResource = imagecreate(800, 350);

    imagecopyresampled(
        $zoomResource,
        $imageResource,
        0,
        0,
        0,
        0,
        $new_width,
        $new_height,
        $width,
        $height
    );

    imagepng($zoomResource, $pathTempPng, 0, PNG_NO_FILTER);
    imagedestroy($zoomResource);

    try {
        $qrcode = new QrReader($pathTempPng);
        $numText = $qrcode->text();
        if ($numText) {
            echo ' FIND ' . $numText . ', ';
            break;
        }
    } catch (\InvalidArgumentException $e) {
        $numText = null;
    }

    echo '{' . $zoom . ' | ' . $numText . ' }, ';
}

The percentage of detected QRcodes increased from 10% to 90% for me.

HermanBilous commented 5 years ago

I had the very same issue happen with me too. I used the hack @githubjeka provided but it ended up giving me 90% success rate too. So I just played around with numbers and found out that usage of zoom step = 5 will increase the success rate even further. I'm planning to add a fallback to https://github.com/dsiddharth2/php-zxing library too. It's a bit slower (around 10 times slower, actually) and also gives me about 90% success rate but on different images. I think I might add another fallback and just try and post my image to https://zxing.org unless it's against website's TOS (would be happy if anyone could enlighten me on the subject).

powtac commented 5 years ago

Both images contain the string w_7585681_2319!

Version 1.0.2 is crashing for this image: CRASH: content_not_detectable_by_QrReader

But works for this image: OK: content_detectable_by_QrReader

Both images contain the string w_7585681_2319!

This is the error message:

Fatal error:  Uncaught InvalidArgumentException in /usr/vendors/php-qrcode-detector-decoder/Qrcode/Decoder/Version.php:121
Stack trace:
#0 /usr/vendors/php-qrcode-detector-decoder/Qrcode/Decoder/Version.php(112): Zxing\Qrcode\Decoder\Version::getVersionForNumber(0)
#1 /usr/vendors/php-qrcode-detector-decoder/Qrcode/Detector/Detector.php(84): Zxing\Qrcode\Decoder\Version::getProvisionalVersionForDimension(17)
#2 /usr/vendors/php-qrcode-detector-decoder/Qrcode/Detector/Detector.php(69): Zxing\Qrcode\Detector\Detector->processFinderPatternInfo(Object(Zxing\Qrcode\Detector\FinderPatternInfo))
#3 /usr/vendors/php-qrcode-detector-decoder/Qrcode/QRCodeReader.php(62): Zxing\Qrcode\Detector\Detector->detect(NULL)
#4 /usr/vendors/php-qrcode-detector-decoder/QrReader.php(80): Zxing\Qrcode\QRCodeReader->decode(Object(Zxing\BinaryBitmap))
#5 /www/htdocs in /usr/vendors/php-qrcode-detector-decoder/Qrcode/Decoder/Version.php on line 121

https://zxing.org/w/decode is able to decode both(!) images with the exact same result:

grafik

A diff shows that most of the dots are inverted on the other version:

grafik

powtac commented 5 years ago

This pull request seems to be related: https://github.com/khanamiryan/php-qrcode-detector-decoder/pull/62 it suppresses the InvalidArgumentException exception. But still is not able to read the code.

Tinywan commented 5 years ago

To fix my issue like as your issue, I used composer require topthink/think-image For example you can see my code:

...
$file_path = $dir_path . '/upload.png';
$image = Image::open($file_path);
$qrReaderPath = $dir_path . '/qrReader.png';
$image->thumb(150, 150)->save($qrReaderPath);
$qrcode = new QrReader($qrReaderPath);
if (!$qrcode->text()) {
    return 'error';
}
return 'success';
shoaib-sme commented 3 years ago

@githubjeka can you please tell me in which file you added this custom code? is it part of QrReader.php? or you created a custom file, from where you call this code?

Thank you.

githubjeka commented 3 years ago

@shoaib-sme in my code. After the try

$qrcode = new QrReader($pathImage);
$numText = $qrcode->text();

if ($numText == null) {
 // this
}
shoaib-sme commented 3 years ago

@githubjeka thank you sir for your quick reply. Cheers :)

EaintHmueThapye98 commented 1 year ago

To fix my issue like as your issue, I used imagecopyresampled For example you can see my code:

$width = imagesx($imageResource);
$height = imagesy($imageResource);

for ($zoom = 100; $zoom >= 10; $zoom -= 10) {
    $new_width = $width * $zoom / 100;
    $new_height = $height * $zoom / 100;
    $zoomResource = imagecreate(800, 350);

    imagecopyresampled(
        $zoomResource,
        $imageResource,
        0,
        0,
        0,
        0,
        $new_width,
        $new_height,
        $width,
        $height
    );

    imagepng($zoomResource, $pathTempPng, 0, PNG_NO_FILTER);
    imagedestroy($zoomResource);

    try {
        $qrcode = new QrReader($pathTempPng);
        $numText = $qrcode->text();
        if ($numText) {
            echo ' FIND ' . $numText . ', ';
            break;
        }
    } catch (\InvalidArgumentException $e) {
        $numText = null;
    }

    echo '{' . $zoom . ' | ' . $numText . ' }, ';
}

The percentage of detected QRcodes increased from 10% to 90% for me.

Your solution saved my day! Thanks a bunch <3