FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour how to scan a barcode presents in a jpeg file
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
how to scan a barcode presents in a jpeg file
Posted: Wed Jan 19, 2022 03:04 PM
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



many thanks
Marco Boschi
info@marcoboschi.it
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: how to scan a barcode presents in a jpeg file
Posted: Wed Jan 19, 2022 03:38 PM

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.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: how to scan a barcode presents in a jpeg file
Posted: Wed Jan 19, 2022 03:43 PM

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.

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: how to scan a barcode presents in a jpeg file
Posted: Wed Jan 19, 2022 04:34 PM

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.

Marc Venken

Using: FWH 23.08 with Harbour
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: how to scan a barcode presents in a jpeg file
Posted: Wed Jan 19, 2022 06:47 PM

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

greeting,

Jimmy
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: how to scan a barcode presents in a jpeg file
Posted: Wed Jan 19, 2022 08:59 PM
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: how to scan a barcode presents in a jpeg file
Posted: Wed Jan 19, 2022 09:11 PM
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: how to scan a barcode presents in a jpeg file
Posted: Thu Jan 20, 2022 07:53 AM
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

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: how to scan a barcode presents in a jpeg file
Posted: Thu Jan 20, 2022 08:39 AM
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: how to scan a barcode presents in a jpeg file
Posted: Thu Jan 20, 2022 08:47 AM
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1091
Joined: Thu Nov 17, 2005 11:08 AM
Re: how to scan a barcode presents in a jpeg file
Posted: Thu Jan 20, 2022 10:28 AM

Many thanks

8)8)

Marco Boschi
info@marcoboschi.it
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: how to scan a barcode presents in a jpeg file
Posted: Thu Jan 20, 2022 11:54 AM
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" ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion