how to scan a barcode presents in a jpeg file

Post Reply
User avatar
MarcoBoschi
Posts: 1072
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

how to scan a barcode presents in a jpeg file

Post 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
Marco Boschi
info@marcoboschi.it
User avatar
karinha
Posts: 7951
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

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

Post 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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
Posts: 7951
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

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

Post 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.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Marc Venken
Posts: 1485
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Post 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.
Marc Venken
Using: FWH 23.08 with Harbour
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

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

Post 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
greeting,
Jimmy
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

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

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

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

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

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

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

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

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

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

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
MarcoBoschi
Posts: 1072
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy
Contact:

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

Post by MarcoBoschi »

8) Many thanks 8)
Marco Boschi
info@marcoboschi.it
User avatar
Antonio Linares
Site Admin
Posts: 42602
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 43 times
Been thanked: 88 times
Contact:

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

Post 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" ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply