js-zxing-pdf417 icon indicating copy to clipboard operation
js-zxing-pdf417 copied to clipboard

Not decoding PDF417 , don't seem to find start pattern

Open liaan opened this issue 6 years ago • 27 comments

Hi,

I have barcode that don't seem to decode, I tried to figure out what the issue is and think its the start pattern that is not correct. There few other sites that is able to decode the barcode, so I know it can be done and I also know the barcode is not 100% according to specs.

Possible you can look at the barcode or maybe give me hint on how I can troubleshoot why start pattern not recognized.. I attach sample

dl_expired

liaan avatar Feb 19 '19 09:02 liaan

Hi @liaan, would you mind add some links to the websites that were able to decode the barcode? Thanks, P.

patriziobruno avatar Feb 19 '19 10:02 patriziobruno

https://online-barcode-reader.inliteresearch.com/ https://demo.dynamsoft.com/dbr/barcodereaderdemo.aspx

liaan avatar Feb 19 '19 10:02 liaan

pattern [8, 1, 2, 1, 1, 1, 1, 3] seems to match, but don't have time now to figure why not decoding ..

liaan avatar Feb 19 '19 11:02 liaan

Ok, dropped the MAX_INDIVIDUAL_VARIANCE to 160 .. , seem to decode now with above change .. I will have to test few more barcodes .. seems like the very poorly printed

liaan avatar Feb 19 '19 13:02 liaan

Would be interesting to hear what project your working on.

rmhrisk avatar Feb 19 '19 13:02 rmhrisk

@rmhrisk Not 100% sure , I;m just tasked with making a function to take a uploaded image of the license disk and decode it so string so string can be passed onto another API for decoding ... problem is, the pdf on license disk don't comply to standard (or very badly printed) so need adjust script to work around it.

liaan avatar Feb 19 '19 13:02 liaan

ok ... not working with other barcodes. Its giving to many error in errorcorrection. will look into this other time

liaan avatar Feb 20 '19 08:02 liaan

Though we believe it is possible to make the necessary improvements to be more accommodating of malformed and low resolution barcodes right now, as a port of the Xing PDF417 functionality, it is fairly picky. Do let us know if you make improvements, we would be glad to take them.

rmhrisk avatar Feb 20 '19 16:02 rmhrisk

@rmhrisk

Ok, made progress .. its reads the first row 100%.
The next row the values are stored, but rownumber is -1 .. I will debug some more later

Sounds to me like image quality is fine, it must be ratio thing or something... will decode more later

Pic of first codeword in second row. image

liaan avatar Feb 21 '19 12:02 liaan

Ok ... just because i'm debugging Here the results from zxing vs Inlite .. now to go figure out why its reading first few columns correct and then loosing the plot :)

Inlite:

\620\924\002\621\590\195\084\230\674\501\046\207\358\137\766\263\277\189\631\243\081\402
\396\327\328\517\182\286\879\674\744\858\200\843\365\442\575\308\759\352\082\486\141\212
\036\824\213\247\414\462\134\406\420\596\522\789\035\017\013\289\029\451\249\704\255\140
\776\148\566\564\037\387\424\050\549\404\418\305\781\396\738\111\396\736\743\197\761\241
\567\667\169\548\015\593\637\525\476\117\732\387\746\389\378\003\705\431\121\380\082\799
\635\093\332\547\231\764\681\140\849\742\527\884\228\247\533\489\353\364\094\378\466\089
\249\744\457\694\872\303\434\221\808\182\328\768\652\837\666\161\670\850\370\265\129\109
\744\590\354\097\840\483\820\003\279\160\790\897\151\338\756\189\407\167\232\415\490\378
\201\249\195\704\821\584\126\707\716\450\347\030\018\258\556\100\409\789\884\316\295\137
\151\310\311\503\170\783\435\792\740\230\571\695\211\243\198\091\496\449\756\197\698\620
\778\335\186\667\372\299\339\075\634\634\490\173\413\580\305\878\280\353\733\162\738\812
\186\219\487\538\477\417\870\665\544\502\393\016\843\281\507\328\250\512\522\442\088\260
\785\327\467\219\717\506\539\558\109\182\727\641\006\302\650\779\327\173\080\478\150\506
\589\007\800\763\652\637\018\694\365\121\274\131\733\860\546\570\330\144\588\265\573\002
\889\505\329\898\156\032\091\411\747\274\547\338\685\387\044\163\259\504\154\289\006\015
\395\515\285\696\517\742\089\183\422\410\176\124\203\028\766\771\804\301\061\657\799\435
\253\298\666\028\402\131\331\443\128\443\080\531\539\551\489\331\159\782\788\608\167\353
\015\266\278\015\116\799\678\398\182\268\704\544\653\396\734\137\146\427\351\790\546\686
\864\134\536\113\725\475\388\662\842\339\324\392\371\181\217\726\338\652\890\104\564\388
\853\620\680\666\426\847\189\132\599\159\234\767\713\862\193\334\595\266\754\372\604\740
\224\333\315\266\073\424\481\219\267\180\534\131\050\632\855\020\674\132\398\096\821\299
\399\119\155\357\358\199\845\844\364\675\122\792\113\104\526\232\442\729\613\585\413\842
\044\511\519\189\034\001\887\829\312\689\818\803\488\038\410\109\128\759\132\413\605\662
\837\008\254\752\242\047\081\113\658\176\898\099\534\404\782\344\360\015\769\784\604\337
\679\324\229\356\364\611\698\327\000\320\018\227\178\633\196\023\499\664\631\157\036\850
\684\762\327\628\263\018\591\189\374\358\127\319\156\036\596\719\464\352\008\063\198\559
\078\779\434\876\314\306\666\221\172\188\393\116\843\851\559\002\060\594\882\489\066\101
\884\732\473\130\088\371\202\524\900\900\900\900\900\900\900\900\900\900\900\900\900\900
\900\900\900\900\023\179\776\333\599\390\846\507\183\889\503\853\016\036\476\862\821\249
\135\120\107\043\737\755\776\369\902\223\130\799\407\076\311\311\601\513\472\516\020\802
\066\161\114\141\186\219\691\599\382\295\285\349\005\623\218\468\053\025\489\888\354\768
\184\417\917\520\333\274\205\395\791\050\186\764\194\182\111\418\119\126\706\470\256\534
\388\353\840\614\450\037\571\055\688\109\338\157\324\211\922\366\100\913\878\786\870\158
\431\760\309\607\289\366\495\078\325\737\418\882\021\517\220\881\263\567\545\369\136\800

Zxing JS


\620\924\002\621\590\195\084\230\000\501\000\207\358\137\766\000\000\841\778\000\402\000
\396\327\328\517\182\286\879\674\744\858\200\000\365\000\575\308\000\719\082\000\860\000
\036\824\213\247\414\462\134\406\420\596\522\789\035\000\013\289\000\451\249\000\000\676
\776\148\566\564\037\387\424\050\549\404\418\305\781\396\738\111\000\000\000\579\493\000
\567\667\169\548\015\593\637\525\476\117\732\387\000\389\378\003\000\000\121\380\082\000
\635\093\332\547\231\764\681\140\849\742\527\884\228\247\533\489\353\364\094\378\466\000
\249\744\457\694\872\303\434\221\808\182\328\768\652\837\666\161\670\850\370\000\129\000
\744\590\354\097\840\483\820\003\279\160\790\897\151\338\756\189\590\167\232\415\490\000
\201\249\195\704\821\584\126\707\716\450\467\030\018\268\556\100\514\789\884\316\000\137
\151\310\311\503\170\783\435\792\740\230\571\000\000\339\198\091\730\000\717\243\000\123
\778\335\186\667\372\299\339\075\634\634\490\173\413\580\305\878\280\353\733\162\738\812
\186\219\487\538\477\417\870\665\544\502\393\016\843\281\507\328\250\512\522\442\000\260
\785\327\467\219\717\348\838\685\746\112\239\351\093\636\793\764\685\000\000\000\669\333
\589\007\800\763\652\637\018\694\365\121\274\131\733\860\546\570\330\144\588\265\573\002
\889\505\329\898\156\032\091\411\747\274\547\338\685\387\044\163\754\709\000\837\912\856
\395\515\285\696\517\742\089\183\422\410\176\124\203\028\766\771\804\301\061\657\799\435
\253\298\666\028\402\131\331\443\128\443\080\531\539\551\489\331\159\782\788\608\167\353
\015\266\278\015\116\799\678\398\182\268\704\544\653\396\734\137\146\427\351\790\000\686
\864\134\536\113\725\475\388\662\842\339\324\392\371\181\217\726\338\652\890\104\564\000
\853\620\680\666\426\847\189\132\599\159\234\767\713\862\000\000\000\034\000\604\740\000
\224\333\315\266\073\424\481\219\267\180\534\131\050\632\855\020\674\132\398\096\000\299
\399\119\155\357\358\199\845\844\364\675\122\792\113\104\526\232\442\729\613\585\413\842
\044\511\519\189\034\001\887\829\312\689\818\803\488\038\410\109\128\759\132\413\000\662
\837\008\254\752\242\047\081\113\658\176\898\099\534\404\782\344\360\015\769\784\000\000
\679\324\229\356\364\611\698\327\000\320\018\227\178\000\196\000\499\000\000\928\000\442
\684\762\327\628\263\018\591\189\374\358\127\319\156\036\596\719\464\352\008\063\000\559
\078\779\434\876\314\306\666\221\172\188\393\116\843\851\559\002\060\594\882\489\066\101
\884\732\473\130\088\371\202\524\900\900\900\900\900\900\900\900\000\000\667\667\667\900
\900\900\900\900\023\179\776\333\599\390\846\507\183\889\503\000\016\036\476\028\821\000
\135\120\107\043\737\755\776\369\902\223\130\799\407\076\311\311\601\513\000\516\020\802
\066\161\114\141\186\219\691\599\382\295\285\349\005\623\218\468\053\025\489\888\212\000
\184\417\917\520\333\274\205\395\791\050\186\000\194\182\111\206\899\000\000\000\000\856
\388\353\840\614\450\037\571\055\688\109\338\157\324\211\922\366\100\913\878\786\870\158
\431\760\309\607\289\366\495\078\325\737\647\882\021\517\220\881\263\000\000\000\000\000

Image used: test3

liaan avatar Feb 22 '19 06:02 liaan

@rmhrisk Any idea what ZXing.PDF417.Internal.PDF417ScanningDecoder.CODEWORD_SKEW_SIZE does ? I thought its the skewness of the row and bigger allow more skew? Reason, changed it to 1 now and decodes barcode better....

liaan avatar Feb 22 '19 07:02 liaan

Found another issue ..... shift right (>>) in JS only support 32 bit .. so decodedBytes.push((value >> (8 * (5 - j1)))); drops the first bits and corrupts data. Busy reworking code to make it work

so following line don't work as expected: decodedBytes.push((value >> (8 * (5 - j1)))); easy test:

var bla = 0b11001101100001001010001010000111100000001
                for(i=0; i <40;i++){
                console.log('bla',bla.toString(2),'i',i,'shifted',((bla >> i)).toString(2));

Output

bla 11001101100001001010001010000111100000001 i 0 shifted 1001010001010000111100000001 
bla 11001101100001001010001010000111100000001 i 1 shifted 100101000101000011110000000 
bla 11001101100001001010001010000111100000001 i 2 shifted 10010100010100001111000000 
bla 11001101100001001010001010000111100000001 i 3 shifted 1001010001010000111100000 
bla 11001101100001001010001010000111100000001 i 4 shifted 100101000101000011110000 
bla 11001101100001001010001010000111100000001 i 5 shifted 10010100010100001111000 
bla 11001101100001001010001010000111100000001 i 6 shifted 1001010001010000111100 
bla 11001101100001001010001010000111100000001 i 7 shifted 100101000101000011110 
bla 11001101100001001010001010000111100000001 i 8 shifted 10010100010100001111 
bla 11001101100001001010001010000111100000001 i 9 shifted 1001010001010000111 
bla 11001101100001001010001010000111100000001 i 10 shifted 100101000101000011 
bla 11001101100001001010001010000111100000001 i 11 shifted 10010100010100001 
bla 11001101100001001010001010000111100000001 i 12 shifted 1001010001010000 
bla 11001101100001001010001010000111100000001 i 13 shifted 100101000101000 
bla 11001101100001001010001010000111100000001 i 14 shifted 10010100010100 
bla 11001101100001001010001010000111100000001 i 15 shifted 1001010001010 
bla 11001101100001001010001010000111100000001 i 16 shifted 100101000101 
bla 11001101100001001010001010000111100000001 i 17 shifted 10010100010 
bla 11001101100001001010001010000111100000001 i 18 shifted 1001010001 
bla 11001101100001001010001010000111100000001 i 19 shifted 100101000 
bla 11001101100001001010001010000111100000001 i 20 shifted 10010100 
bla 11001101100001001010001010000111100000001 i 21 shifted 1001010 
bla 11001101100001001010001010000111100000001 i 22 shifted 100101 
bla 11001101100001001010001010000111100000001 i 23 shifted 10010 
bla 11001101100001001010001010000111100000001 i 24 shifted 1001 
bla 11001101100001001010001010000111100000001 i 25 shifted 100 
bla 11001101100001001010001010000111100000001 i 26 shifted 10 
bla 11001101100001001010001010000111100000001 i 27 shifted 1 
bla 11001101100001001010001010000111100000001 i 28 shifted 0 
bla 11001101100001001010001010000111100000001 i 29 shifted 0 
bla 11001101100001001010001010000111100000001 i 30 shifted 0 
bla 11001101100001001010001010000111100000001 i 31 shifted 0 
bla 11001101100001001010001010000111100000001 i 32 shifted 1001010001010000111100000001 
bla 11001101100001001010001010000111100000001 i 33 shifted 100101000101000011110000000 
bla 11001101100001001010001010000111100000001 i 34 shifted 10010100010100001111000000 
bla 11001101100001001010001010000111100000001 i 35 shifted 1001010001010000111100000 
bla 11001101100001001010001010000111100000001 i 36 shifted 100101000101000011110000 
bla 11001101100001001010001010000111100000001 i 37 shifted 10010100010100001111000 
bla 11001101100001001010001010000111100000001 i 38 shifted 1001010001010000111100 
bla 11001101100001001010001010000111100000001 i 39 shifted 100101000101000011110

liaan avatar Feb 22 '19 14:02 liaan

Just a hint: ByteStream.js has class BitStream which supports right and left shifting for unlimited data.

YuryStrozhevsky avatar Feb 22 '19 14:02 YuryStrozhevsky

Just a hint: ByteStream.js has class BitStream which supports right and left shifting for unlimited data.

Thanks ... trying to use BigInteger's shiftRight function seeing its already included.

liaan avatar Feb 22 '19 14:02 liaan

seems to work with this

ZXing.PDF417.Internal.DecodedBitStreamParser.byteCompaction = function (p) {
    var mode = p.mode, codewords = p.codewords, codeIndex = p.codeIndex;
    
    var decodedBytes = [];
    var count = 0;
    //var value = 0;
    var value = new bigInt(0);
    //console.log('new value',value.shiftRight(1).toString(2));
    var end = false;
    if (mode == 901) {
        count = 0;
        value =bigInt(0);
        var byteCompactedCodewords = new Int32Array(6);
        end = false;
        var nextCode = codewords[codeIndex++];
        while ((codeIndex < codewords[0]) && !end) {
            byteCompactedCodewords[count++] = nextCode;
//            value = 900 * value + nextCode;
            value = bigInt(900 * value + nextCode);
            nextCode = codewords[codeIndex++];
            if (nextCode == 900 || nextCode == 901 || nextCode == 902 || nextCode == 924 || nextCode == 928 || nextCode == 923 || nextCode == 922) {
                codeIndex--;
                end = true;
            }
            else {
                if ((count % 5 === 0) && (count > 0)) {
                    
                    for (var j = 0; j < 6; ++j) {
                        
                     
                        decodedBytes.push((value >> (8 * (5 - j))));
                    }
                    value = 0;
                    count = 0;
                }
            }
        }
        if (codeIndex == codewords[0] && nextCode < 900)
            byteCompactedCodewords[count++] = nextCode;
        for (var i = 0; i < count; i++) {
            decodedBytes.push(byteCompactedCodewords[i]);
        }
    } else if (mode == 924) {
        count = 0;
        value = bigInt(0);
        end = false;
        
        while (codeIndex < codewords[0] && !end) {
            var code = codewords[codeIndex++];
            if (code < 900) {
                count++;
                value = bigInt(900 * value + code);
                //  console.log('val2',value)
                  //console.log('code',code)
            }
            else {
                if (code == 900 || code == 901 || code == 902 || code == 924 || code == 928 || code == 923 || code == 922) {
                    codeIndex--;
                    end = true;
                }
            }
            if ((count % 5  == 0) && (count > 0)) {
                for (var j1 = 0; j1 < 6; ++j1) {
                  //  value.shiftRight(6)
                    decodedBytes.push((value.shiftRight(8 * (5 - j1))));
                    //console.log(typeof value.shiftRight(5))
                    //console.log('values',value, '', 8 * (5 - j1),(value >> (8 * (5 - j1))));
                }
                //console.log('val',value)
                
                
                value = 0;
                count = 0;
            }
            
        }
    }
     //console.log('bla',String.fromCharCode.apply(null, decodedBytes))
    p.result += (String.fromCharCode.apply(null, decodedBytes));
    return codeIndex;
};

liaan avatar Feb 22 '19 15:02 liaan

Progress!

rmhrisk avatar Feb 22 '19 16:02 rmhrisk

@liaan do I understand correctly you think you found what the core issue was and are now able to use the library for your use case?

rmhrisk avatar Feb 22 '19 16:02 rmhrisk

@rmhrisk Any idea what ZXing.PDF417.Internal.PDF417ScanningDecoder.CODEWORD_SKEW_SIZE does ? I thought its the skewness of the row and bigger allow more skew? Reason, changed it to 1 now and decodes barcode better....

@patriziobruno can you explain?

rmhrisk avatar Feb 22 '19 20:02 rmhrisk

@liaan do I understand correctly you think you found what the core issue was and are now able to use the library for your use case?

Well .. it decodes the barcode .. but only 80% of data is correct, rest is wrong. I would have thought with 6x error correction it would be 100% correct. So either the error correction code is buggy or there even more typo's in code.

I will spend more time on it at some point

liaan avatar Feb 25 '19 06:02 liaan

Mind sending a PR with you’re changes so far?

rmhrisk avatar Feb 25 '19 07:02 rmhrisk

@rmhrisk, @liaan is right that's the max threshold for the "skewness"

patriziobruno avatar Feb 27 '19 16:02 patriziobruno

@liaan - Did you manage to get this working for the South African Drivers license?

shaunmauer avatar Jun 05 '19 21:06 shaunmauer

@liaan - Did you manage to get this working for the South African Drivers license?

Morning, No, the library don't follow PDF417 standards correctley and simply don't have time to fix all the problems. I got it to scan most of the ID's but the error detection/redundancy part of the library seems to be very buggy so never produce correct output unless its 100% correctley scanned, it does not fix problems as it should (PDF417 have >6 times redundancy).

liaan avatar Jun 06 '19 05:06 liaan

@liaan if you do have fixes we would love to have them, we will find time to get back to this library again in the not so distant future.

rmhrisk avatar Jun 06 '19 06:06 rmhrisk

Any news?

shkarab avatar Jul 10 '19 05:07 shkarab

No update

rmhrisk avatar Jul 10 '19 05:07 rmhrisk

seems to work with this

ZXing.PDF417.Internal.DecodedBitStreamParser.byteCompaction = function (p) {
    var mode = p.mode, codewords = p.codewords, codeIndex = p.codeIndex;
    
    var decodedBytes = [];
    var count = 0;
    //var value = 0;
    var value = new bigInt(0);
    //console.log('new value',value.shiftRight(1).toString(2));
    var end = false;
    if (mode == 901) {
        count = 0;
        value =bigInt(0);
        var byteCompactedCodewords = new Int32Array(6);
        end = false;
        var nextCode = codewords[codeIndex++];
        while ((codeIndex < codewords[0]) && !end) {
            byteCompactedCodewords[count++] = nextCode;
//            value = 900 * value + nextCode;
            value = bigInt(900 * value + nextCode);
            nextCode = codewords[codeIndex++];
            if (nextCode == 900 || nextCode == 901 || nextCode == 902 || nextCode == 924 || nextCode == 928 || nextCode == 923 || nextCode == 922) {
                codeIndex--;
                end = true;
            }
            else {
                if ((count % 5 === 0) && (count > 0)) {
                    
                    for (var j = 0; j < 6; ++j) {
                        
                     
                        decodedBytes.push((value >> (8 * (5 - j))));
                    }
                    value = 0;
                    count = 0;
                }
            }
        }
        if (codeIndex == codewords[0] && nextCode < 900)
            byteCompactedCodewords[count++] = nextCode;
        for (var i = 0; i < count; i++) {
            decodedBytes.push(byteCompactedCodewords[i]);
        }
    } else if (mode == 924) {
        count = 0;
        value = bigInt(0);
        end = false;
        
        while (codeIndex < codewords[0] && !end) {
            var code = codewords[codeIndex++];
            if (code < 900) {
                count++;
                value = bigInt(900 * value + code);
                //  console.log('val2',value)
                  //console.log('code',code)
            }
            else {
                if (code == 900 || code == 901 || code == 902 || code == 924 || code == 928 || code == 923 || code == 922) {
                    codeIndex--;
                    end = true;
                }
            }
            if ((count % 5  == 0) && (count > 0)) {
                for (var j1 = 0; j1 < 6; ++j1) {
                  //  value.shiftRight(6)
                    decodedBytes.push((value.shiftRight(8 * (5 - j1))));
                    //console.log(typeof value.shiftRight(5))
                    //console.log('values',value, '', 8 * (5 - j1),(value >> (8 * (5 - j1))));
                }
                //console.log('val',value)
                
                
                value = 0;
                count = 0;
            }
            
        }
    }
     //console.log('bla',String.fromCharCode.apply(null, decodedBytes))
    p.result += (String.fromCharCode.apply(null, decodedBytes));
    return codeIndex;
};

I have got the same codewords as inlite returns but after that, ByteCompaction return decodedbytes with values 1, 411, 105225, 26937669, 1765387075584 for initial codewords and then

p.result += (String.fromCharCode.apply(null, decodedBytes));

the above line returns

ƛ鬉ॅ䔀ƛ鬉ॅ䔀‰覱녖噧枬걗Õ햷랋譚媅藑q焲㋒튞鹴瑆ì蒙餤⒄蒊«ꬾ㺼뱭浮滚w矧ヽﴩ⦷¸롋䬇߾ﻁ쇮T呇䜭ⴵ㖥ꗵ“鎪ꨟὣ掌谎ûffl҉覡ꇧ ਧ✯⼧❲爇•锌೓펠ꃌ차X墰낮껗ퟨýﴊ૨ꮀ胂¶뚄葾繅䖇蟷ì쨘ᣱⷽ逯⾑

Philanthropist80 avatar Aug 26 '19 13:08 Philanthropist80