Page 1 of 1
Convert PDF -> Picture -> Read Barcode
Posted: 2010-01-10T23:54:30-07:00
by dranakan
Hello,
My goal is to read some barcode (qrcode with
http://zbar.sourceforge.net/) printed on sheets. I am using a scanner (creating PDF) and the powerful ImageMagick to convert PDF to JPG.
Process :
Code: Select all
[On a sheet one barcode] -> [Scan 200 DPI] -> [PDF] -> [JPG] -> [Read barcode with Zbar]
The barcode is in black and white like this :
http://www.goglocal.net/wp-content/uplo ... QRCode.jpg in size of 1.8x1.8 cm. The size Page is principally A4 but could be others.
I need your help to find the best options to convert my PDF into JPG. For the moment I use :
Code: Select all
convert -blur 0 -density 150 -quality 100 -threshold 50% source.PDF dest.jpg
The capacity of Zbar to read barcode depends of the quality of the convertion.
What can I set to have best results whitout spending a lot of CPU time (I can use density 300 and get best results but it takes a lot of times).
After some tests, I hesiste between density 150 and 200 (time and quality) with what is it better to use density 150 instead of 170 ? Higher the density is, better will be the result ? No ?
Thanks
![Smile :-)](./images/smilies/icon_smile.gif)
Re: Convert PDF -> JPG -> Read Barcode
Posted: 2010-01-11T08:22:25-07:00
by el_supremo
Just out of curiosity I installed zbar (Windows version) and tried it on your sample image. It decoded it with no problem at all.
However, I'd suggest that you save your image as GIF or PNG. The JPG format isn't intended for black and white images and its compression will add some blurring around the edges of the barcodes.
For the density, I suspect that you could get away with a lower value but you'd have to experiment to find out at what point it starts to produce poor results from zbar.
You don't need "-blur 0" in your convert command and for GIF format you won't need "-quality 100". If you output to PNG, use "-quality 95".
Pete
Re: Convert PDF -> JPG -> Read Barcode
Posted: 2010-01-11T09:45:10-07:00
by dranakan
Thank you el_supremo
>>It decoded it with no problem at all
Zbar is able to read from PDF but the quality of detection is not very good. Try (if you want) this one :
http://www.megaupload.com/?d=ZYECDWZ7 (PDF scan in OCR 200 DPI)
This is 20 qrcode and zbar is able to recognize 5.
and see result :
Code: Select all
scanned 5 barcode symbols from 20 images
You can try to convert in jpg with options :
Code: Select all
convert -blur 0 -density 150 -quality 100 -threshold 55% Test1.8_20QrCodes.pdf o.jpg
zbarimg *.jpg
With the result :
Code: Select all
scanned 20 barcode symbols from 20 images
You don't need "-blur 0" in your convert command and for GIF format you won't need "-quality 100". If you output to PNG, use "-quality 95".
Code: Select all
convert -density 150 -quality 100 -threshold 55% Test1.8_20QrCodes.pdf o.png
-> scanned 19 barcode symbols from 20 images
convert -density 150 -quality 95 -threshold 55% Test1.8_20QrCodes.pdf o.png
-> scanned 19 barcode symbols from 20 images
convert -blur 0 -density 150 -quality 95 -threshold 55% Test1.8_20QrCodes.pdf o.png
-> scanned 20 barcode symbols from 20 images
convert -density 150 -quality 100 -threshold 55% Test1.8_20QrCodes.pdf o.gif
-> scanned 19 barcode symbols from 20 images
convert -blur 0 -density 150 -quality 95 -threshold 55% Test1.8_20QrCodes.pdf o.gif
-> scanned 20 barcode symbols from 20 images
convert -blur 0 -density 150 -quality 100 -threshold 55% Test1.8_20QrCodes.pdf o.gif
-> scanned 20 barcode symbols from 20 images
-blur 0 seems to be necessary. Tomorrow I will measure the fastest between. jpg, gif and. png.
Re: Convert PDF -> JPG -> Read Barcode
Posted: 2010-01-11T12:40:15-07:00
by el_supremo
Zbar is able to read from PDF but the quality of detection is not very good
I presume that zbar is using ImageMagick to process the PDF image. It finds 5 barcodes in the 20 images. If you use IM to process the PDF to GIF files using a density of 72 then zbar still only recognizes 5 of the codes. This suggests that zbar uses ImageMagick's default density of 72dpi when processing PDF files. There's no option in zbar to increase this value - it does seem to have an option to decrease the density but you can't increase it. If zbar is still being developed you could ask that a command line option be added to increase ImageMagick's density when processing PDF files - and while they're at it, allow you to set the threshold because the detection will be sensitive to that as well.
-blur 0 seems to be necessary
In the tests I have done, adding blur makes it worse and if you look at the resulting images you would expect that to be the case. I thought that using -sharpen might help but if the barcode itself is small the sharpening also seems to make the image harder for zbar to read. It would be best if you don't need blur or sharpen because they'll add extra time to the processing.
The command I have been using is this:
Code: Select all
convert -density 100 -threshold 55% Test1.8_20QrCodes.pdf +adjoin test100.gif
The +adjoin forces IM to write each PDF page as a separate GIF file which will be named in sequence, test100-0.gif, test100-1.gif etc.
Pete
Re: Convert PDF -> JPG -> Read Barcode
Posted: 2010-01-11T19:05:34-07:00
by fmw42
use supersampling to get better quality from the pdf
convert -density 288 image.pdf -resize 25% -threshold XX% image.gif
Re: Convert PDF -> Picture -> Read Barcode
Posted: 2010-01-12T02:47:01-07:00
by dranakan
Hello,
Thank you el_supremo.
I test the export in .jpg and in .gif. My test file has 69 barcodes (qrcodes from 1.8x1.8 cm and scan with a Scan Station 500 in 200 DPI in OCR). To read all barcodes, the command with JPG need a density of 160 and with GIF a density of 150.
IM version 6.2.8 03/31/08 Q16 on RHEL 5.
JPG (3m30s):
Code: Select all
Tue Jan 12 09:56:34 CET 2010
convert -blur 0 -density 160 -quality 100 -threshold 55% All1.8_59qrcodes.pdf o.jpg
Tue Jan 12 10:00:13 CET 2010
scanned 69 barcode symbols from 65 images in 40 seconds
Tue Jan 12 10:00:53 CET 2010
GIF (1m30s):
Code: Select all
Tue Jan 12 10:00:53 CET 2010
convert -density 150 -threshold 55% All1.8_59qrcodes.pdf +adjoin o.gif
Tue Jan 12 10:02:19 CET 2010
scanned 69 barcode symbols from 65 images in 36 seconds
Tue Jan 12 10:02:55 CET 2010
Fmw42, thank you.
I have tried this :
Code: Select all
convert -density 150 image.pdf -resize 25% -threshold XX% image.gif
convert -density 150 image.pdf -resize 25% -threshold 55% image.gif
convert -density 150 image.pdf -resize 25% -threshold 55% +adjoin image.gif
convert -density 200 image.pdf -resize 25% -threshold 55% image.gif
But I can get good results with good performances...
My conclusion :
The best command to get good performances/quality to do : PDF->Picture->Read barcode is :
Code: Select all
convert -density 150 -threshold 55% SOURCE.pdf +adjoin DEST.gif
Re: Convert PDF -> Picture -> Read Barcode [Memory use]
Posted: 2010-05-04T00:49:49-07:00
by dranakan
Hello,
I am using this command. It works fine but I have some problems with large PDF...
Code: Select all
convert -density 150 -threshold 55% SOURCE.pdf +adjoin DEST.gif
I have tested to scan a big PDF (130 mb, 780 pages) and it need more than 20gb...
How can I decrease the quantity of memory used to do that (other than spliting the Pdf) ?
Thanks
Re: Convert PDF -> Picture -> Read Barcode
Posted: 2010-05-04T23:11:55-07:00
by dranakan
All is ok...
I split PDF's (1 new PDF for each page) and all is ok.
Re: Convert PDF -> Picture -> Read Barcode
Posted: 2010-05-06T00:10:23-07:00
by dranakan
Hello,
I have done other tests with other samples, sometime the barcode (same size) are not recognize. Increasing the density give not best results.
For exemple :
Sample_A, OK with density 184 but not with 185
Sample_B, not ok with density 185 but ok with 184.
What is your advise to find the good configuration for always reading the barcodes...
Thanks
Re: Convert PDF -> Picture -> Read Barcode
Posted: 2013-04-14T21:02:23-07:00
by fmw42
You really should have started a new thread and not tacked this question onto an old one (unless you are just advertising here for the linked bar code application). (It was advertising and was removed -- Ant)
A png converted to pdf in Imagemagick will just be a png image with a vector wrapper. It will not be a fully vector file. If that is what you want, you can convert any raster image to pdf with Imagemagick. There are other tools that will let you extract the raster image from the vector PDF wrapper, but you cannot do that in Imagemagick. It will convert the pdf to png again, but it will not be like pulling the png out of the pdf directly, as I understand it.
Re: Convert PDF -> Picture -> Read Barcode
Posted: 2013-04-14T21:29:59-07:00
by anthony
IM uses ghostscript to read a PDF image. As such Raster image in a PDF will be 'rendered. according to the rendering (drawing) density and the PDF's own handling, placement, warping or resizing of the raster image.
PDFimage is a program that can extract the raw raster image data from a PDF without regard to the density or other 'modification', however it is not guaranteed to work in all cases. Does for most cases however.