php-qrcode-detector-decoder icon indicating copy to clipboard operation
php-qrcode-detector-decoder copied to clipboard

Wrong result

Open powtac opened this issue 9 years ago • 25 comments
trafficstars

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 avatar Feb 18 '16 12:02 powtac

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

wrong2

powtac avatar Feb 18 '16 15:02 powtac

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

jlemale avatar Mar 02 '16 16:03 jlemale

Those images where created by a PHP library, TCPDF

powtac avatar Mar 02 '16 16:03 powtac

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 ?

jlemale avatar Mar 02 '16 17:03 jlemale

Default settings

powtac avatar Mar 02 '16 17:03 powtac

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

powtac avatar Mar 02 '16 17:03 powtac

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

jlemale avatar Mar 02 '16 17:03 jlemale

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 avatar Mar 02 '16 19:03 powtac

Similar to #9, #12 and #13

powtac avatar Mar 04 '16 09:03 powtac

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

jamiedunns avatar Mar 09 '16 13:03 jamiedunns

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

qhxin avatar Dec 26 '16 07:12 qhxin

I have not solved it.

powtac avatar Dec 26 '16 07:12 powtac

@powtac

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

https://github.com/qhxin/qhQrCodeReader

qhxin avatar Dec 27 '16 15:12 qhxin

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..

jlemale avatar Dec 27 '16 15:12 jlemale

Actually I made the same kind of workaround.

Am 27.12.2016 um 16:49 schrieb jlemale [email protected]:

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.

powtac avatar Dec 27 '16 16:12 powtac

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.😂

qhxin avatar Dec 28 '16 02:12 qhxin

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.

githubjeka avatar Jul 05 '17 13:07 githubjeka

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).

HermanBilous avatar Sep 17 '18 12:09 HermanBilous

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 avatar May 21 '19 09:05 powtac

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.

powtac avatar May 24 '19 09:05 powtac

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';

Tinywan avatar May 24 '19 14:05 Tinywan

@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.

shoaib-sme avatar Jun 01 '21 09:06 shoaib-sme

@shoaib-sme in my code. After the try

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

if ($numText == null) {
 // this
}

githubjeka avatar Jun 02 '21 05:06 githubjeka

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

shoaib-sme avatar Jun 02 '21 06:06 shoaib-sme

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

EaintHmueThapye98 avatar Apr 20 '23 04:04 EaintHmueThapye98