how to scan a barcode presents in a jpeg file

how to scan a barcode presents in a jpeg file

Postby MarcoBoschi » Wed Jan 19, 2022 3: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

Image

many thanks
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

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

Postby karinha » Wed Jan 19, 2022 3: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
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

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

Postby karinha » Wed Jan 19, 2022 3: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
User avatar
karinha
 
Posts: 7808
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

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

Postby Marc Venken » Wed Jan 19, 2022 4: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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1426
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

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

Postby Jimmy » Wed Jan 19, 2022 6: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
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

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

Postby Antonio Linares » Wed Jan 19, 2022 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Wed Jan 19, 2022 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Thu Jan 20, 2022 7: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

Image
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Thu Jan 20, 2022 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby Antonio Linares » Thu Jan 20, 2022 8: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

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

Postby MarcoBoschi » Thu Jan 20, 2022 10:28 am

8) Many thanks 8)
User avatar
MarcoBoschi
 
Posts: 1065
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

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

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 106 guests