Page 1 of 1

how to scan a barcode presents in a jpeg file

PostPosted: Wed Jan 19, 2022 3:04 pm
by MarcoBoschi
Hi,
I have a jpeg file that contains a barcode
Is it possible to create a function to which passed the file name as parameter manages to open it and interpret the barcode code?

http://www.marcoboschi.it/public/barcode.jpg

Image

many thanks

Re: how to scan a barcode presents in a jpeg file

PostPosted: Wed Jan 19, 2022 3:38 pm
by karinha
Hola, ¿tienes un lector de código de barras de teclado? Si lee, puede usar HBCOMM.LIB para leer cualquier GET.

Hello, do you have a Keyboard Barcode READER? If it reads, you can use HBCOMM.LIB to read any GET.

Regards, saludos.

Re: how to scan a barcode presents in a jpeg file

PostPosted: Wed Jan 19, 2022 3:43 pm
by karinha
Para probar, utilice el Keyboard Reader mediante el comando PROMPT, o en cualquier editor de texto tipo EditPad.exe para ver si el código sale intacto en el editor o en el comando PROMPT.

To test, use the Keyboard Reader via command PROMPT, or in any text editor type EditPad.exe to see if the code comes out intact in the editor or in the command PROMPT.

Regards, saludos.

Re: how to scan a barcode presents in a jpeg file

PostPosted: Wed Jan 19, 2022 4:34 pm
by Marc Venken
Do mean that the images will be read and that you want to read the barcode without scanning it with a barcode reader ?
Not seen this in the forum.

Scanning is like Karinha says. We can provide a sample if needed.

Re: how to scan a barcode presents in a jpeg file

PostPosted: Wed Jan 19, 2022 6:47 pm
by Jimmy
hi,

you can use GetPixel() Function to read each Pixel of a Image.
while Barcode have only B/W Result is easy to identify

but it is a very slow Solution

Re: how to scan a barcode presents in a jpeg file

PostPosted: Wed Jan 19, 2022 8:59 pm
by Antonio Linares
Marco,

You can use the OpenCV (open computer vision) library to do it:
https://github.com/dnosit/python-opencv-barcode-automation
https://www.pyimagesearch.com/2018/05/21/an-opencv-barcode-and-qr-code-scanner-with-zbar/

Please search for opencv on these forums to review other posts about it and how to use it from Harbour

Re: how to scan a barcode presents in a jpeg file

PostPosted: Wed Jan 19, 2022 9:11 pm
by Antonio Linares
This is a shared google colab doc with the code to review it and run it right there:

https://colab.research.google.com/drive/11afb45vJxBq0pCcwuYxsTP4vfPHHgVDK?usp=sharing

Once you get it running there, then you can call it from Harbour

Re: how to scan a barcode presents in a jpeg file

PostPosted: Thu Jan 20, 2022 7:53 am
by Antonio Linares
Working with a right barcode, and it detects multiple barcodes :-)

two lines of code do the magic:
frame = cv2.imread( 'marco.jpg' )
barcodes = pyzbar.decode( frame )

it properly detects the right one:
1
1234567890128
EAN13

Image

Re: how to scan a barcode presents in a jpeg file

PostPosted: Thu Jan 20, 2022 8:39 am
by Antonio Linares
Marco,

zbar library for C++: (opencv only supports C++)
http://zbar.sourceforge.net/download.html

combining opencv and zbar you can do it. Google colab let us quickly test opencv (most examples are in python and C++)
and then, once you are satisfied with the results, the code gets ported to C++ or you call python from your Harbour app

Here we have a full example in C++, but we can simplify it very much:
https://stackoverflow.com/questions/56068886/how-to-configure-c-zbar-scanner-to-decode-only-qr-code-data-type

Re: how to scan a barcode presents in a jpeg file

PostPosted: Thu Jan 20, 2022 8:47 am
by Antonio Linares
It seems as the zbar library already provide several utilities that surely do it automatically, so you just need to run it from your app :-)

ZBar Bar Code Reader is an open source software suite for reading bar codes
from various sources, such as video streams, image files and raw intensity
sensors. It supports EAN-13/UPC-A, UPC-E, EAN-8, Code 128, Code 39,
Interleaved 2 of 5 and QR Code. Included with the library are basic
applications for decoding captured bar code images and using a video device
(eg, webcam) as a bar code scanner. For application developers, language
bindings are included for C, C++, Python and Perl as well as GUI widgets for
Qt, GTK and PyGTK.

Check the ZBar home page for the latest release, mailing lists, etc.
http://zbar.sourceforge.net/


Please download it and test the built in utilities from here:
http://sourceforge.net/projects/zbar/files/zbar/0.10/zbar-0.10-setup.exe/download

Re: how to scan a barcode presents in a jpeg file

PostPosted: Thu Jan 20, 2022 10:28 am
by MarcoBoschi
8) Many thanks 8)

Re: how to scan a barcode presents in a jpeg file

PostPosted: Thu Jan 20, 2022 11:54 am
by Antonio Linares
c:\Program Files (x86)\ZBar\bin>zbarimg marco.jpg
EAN-13:1234567890128
scanned 1 barcode symbols from 1 images


So you can call it using WinExec(), WaitRun(), hb_Run(), etc. and read the output :-)

WaitRun( "c:\Program Files (x86)\ZBar\bin>zbarimg " + "marco.jpg" + " > info.txt" )
MsgInfo( MemoRead( "info.txt" ) )