mubaidr / Javascript-Barcode-Reader

Simple and Fast Barcode decoder with support of Code128, Code93, Code39, Standard/Industrial 2 of 5, Interleaved 2 of 5, Codabar, EAN-13, EAN-8 barcodes in javascript.
https://mubaidr.js.org/Javascript-Barcode-Reader/
MIT License
190 stars 28 forks source link

code-128 #272

Closed joseph-animasds closed 5 years ago

joseph-animasds commented 5 years ago

Describe the bug When reading a png image of only the barcode and using the code-128 decoder, An error is thrown "Failed to extract barcode" Here is my code: image

image

image Here is the error: image

Desktop (please complete the following information):

mubaidr commented 5 years ago

Please share the image you are trying to use.

mubaidr commented 5 years ago

I am sorry but I still cannot see the barcode image. :(

Attachment to email might not work, please attach image here.

mubaidr commented 5 years ago

Attachment to email might not work, please attach image here.

Email does not show any image.

mubaidr commented 5 years ago

@joseph-animasds please donot post image via email, it does not work. Instead visit this link and drag n drop image to add it to comment, please. https://github.com/mubaidr/Javascript-Barcode-Reader/issues/272

joseph-animasds commented 5 years ago

Here is image croppedImage

mubaidr commented 5 years ago

Sorry for inconvenience. I will look into this matter soon.

joseph-animasds commented 5 years ago

Im also trying this image which is higher resolution. It works using this tool https://demo.dynamsoft.com/DBR/BarcodeReaderDemo.aspx but with this package it does not work croppedImage

joseph-animasds commented 5 years ago

@mubaidr - any update yet?

mubaidr commented 5 years ago

For the above image: Expected: "33c64780-a9c0-e92a-820c-fae7011c11e2" Received: "33ETX4780-SOH9ETX0-ENQ2SOH80ETX-SOHENQ70111ENQ2"

Looks like this package is not decoding code-128 properly. I am working on it.

mubaidr commented 5 years ago

Interesting: So if I try to use this online service to generate image for same code, it is extracted by this package as expected.

https://barcode.tec-it.com/en/?data=33c64780-a9c0-e92a-820c-fae7011c11e2 33c64780-a9c0-e92a-820c-fae7011c11e2

joseph-animasds commented 5 years ago

@mubaidr - I first have a pdf that I convert with linux: pdftoppm test.pdf test -png -f 1 -singlefile -rx 300 -ry 300 then I crop that image and run this javascript-barcode-reader: ` const express = require('express') const app = express() const port = 3000 const sharp = require('sharp'); const javascriptBarcodeReader = require('javascript-barcode-reader')

app.get('/', (req, res) => { let originalImage = 'pdf/test.png' // file name for cropped image let croppedImage = 'croppedImage/croppedImage.png';

sharp(originalImage).extract({ width: 1114, height: 105, left: 789, top: 3189 }).toFile(croppedImage)
    .then(new_file_info => {
        console.log("Image cropped and saved", new_file_info);
        javascriptBarcodeReader(
            croppedImage /* Image file Path || {data: pixelArray, width, height} || HTML5 Canvas ImageData */,
            {
                barcode: 'code-128',
                type: 'industrial', //optional type
            }
        )
            .then(code => {
                console.log(code)
            })
            .catch(err => {
                console.log(err)
            })
    }).catch(err => console.log(err, "something failed"))

})

app.listen(port, () => console.log(listening on ${port})) `

joseph-animasds commented 5 years ago

@mubaidr - the image is a little blurry when I zoom in. I think that is why.

mubaidr commented 5 years ago

Actually i have compared two images using an online image difference tool. Looks like there are atleast two portions in your provided image which are different than the above generated Image (uploaded by me). So i think it is related to some encoding configuration.

joseph-animasds commented 5 years ago

@mubaidr - Are you working on a fix then?

mubaidr commented 5 years ago

Yes, I am working on it. Stay tuned!

mubaidr commented 5 years ago

Fixed in: https://github.com/mubaidr/Javascript-Barcode-Reader/commit/7536e9882c51717b20d96fe38364b3135034729b

You may still note that some characters cannot be identified, this is due to image degradation issue. I will be adding feature to pre-process image to enhance its precision. You can follow it up here: https://github.com/mubaidr/Javascript-Barcode-Reader/issues/250