Recent

Author Topic: QR code reading with cam  (Read 28661 times)

makgab

  • Jr. Member
  • **
  • Posts: 55
QR code reading with cam
« on: March 04, 2016, 09:47:48 pm »
Hi!
How can I read a QR code from camera (ex. webcamera)?
The LazBarcode component can generate QR code (not reading).
I would like to read QR code (decode to string) and process it.
 
Is there any component or solution for this?


avra

  • Hero Member
  • *****
  • Posts: 2593
    • Additional info
Re: QR code reading with cam
« Reply #1 on: March 07, 2016, 12:15:43 pm »
Maybe trying to use some existing Delphi code?
https://github.com/Spelt/ZXing.Delphi
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: QR code reading with cam
« Reply #2 on: March 07, 2016, 12:37:45 pm »
hello,
there is also  DelphiZXingQRCodeEx

Quote
DelphiZXingQRCodeEx is a Delphi port of the QR Code functionality from ZXing, an open source barcode image processing library.

The code was initially ported to Delphi by Senior Debenu Developer, Kevin Newman (project DelphiZXingQRCode, see links below). Then it was changed by Michael Demidov. The changes are listed in CHANGELOG.md.

The most fundamental differences are:

Error correction level has been fixed.
Support for programmer-defined charsets. As an example, I implemented Win-1251 Russian charset and URL encoding (when non-Latin characters are represented as %-codes).
Exception handling has been added. There is no more Access Violation when input string is too long.
New QRGraphics.pas unit has been added that contains several functions to draw the QR Code on a given canvas (TCanvas) and to generate either a bitmap or a metafile.
Still compatible with older versions of Delphi (at least Delphi 7). Compatible with Lazarus (1.2.6, for Windows), see CHANGELOG.md (section 5).
The port retains the original Apache License (v2.0).

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

avra

  • Hero Member
  • *****
  • Posts: 2593
    • Additional info
Re: QR code reading with cam
« Reply #3 on: March 07, 2016, 01:11:37 pm »
there is also  DelphiZXingQRCodeEx
Are you sure that it can decode QR, and not just generate QR?
ct2laz - Conversion between Lazarus and CodeTyphon
bithelpers - Bit manipulation for standard types
pasettimino - Siemens S7 PLC lib

makgab

  • Jr. Member
  • **
  • Posts: 55
Re: QR code reading with cam
« Reply #4 on: March 07, 2016, 01:36:34 pm »
I would like to use platform independent solution. I try to use opencv and zbar...

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: QR code reading with cam
« Reply #5 on: March 07, 2016, 01:51:15 pm »
oops  :-[   sorry Avra,
it seems that the project   DelphiZXingQRCodeEx is a QRcode encoder not a decoder.
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: QR code reading with cam
« Reply #6 on: March 09, 2016, 04:28:39 am »
hello,
using tprocess and zbarimg command line program , you can decode qr code image (BarCodeFile is a qrcode image file) :

code example Lazarus 1.6 Windows 7 :
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ReadBarCode(BarCodeFile : String);
  2.       const READ_BYTES = 2048;
  3.       var
  4.       aProcess: TProcess; //TProcess is crossplatform is best way
  5.       MemStream: TMemoryStream;
  6.       NumBytes: LongInt;
  7.       BytesRead: LongInt;
  8.       Lines: TStringList;
  9.     begin
  10.      // A temp Memorystream is used to buffer the output
  11.      MemStream := TMemoryStream.Create;
  12.      Lines :=TStringList.Create;
  13.      BytesRead := 0;
  14.  
  15.        aProcess := TProcess.Create(nil);
  16.        aProcess.Executable := 'zbarimg.exe';
  17.        aProcess.Parameters.Add('-q');
  18.        aProcess.Parameters.Add(BarCodeFile);
  19.        aprocess.ShowWindow := swoHIDE;
  20.        AProcess.Options := AProcess.Options + [poUsePipes,poStderrToOutPut];
  21.        Memo1.Lines.Clear;
  22.        Memo1.Lines.Add('Trying to decode BarCode Image  ...');
  23.        aProcess.Execute;
  24.        while aProcess.Running do
  25.        begin
  26.          // make sure we have room
  27.          MemStream.SetSize(BytesRead + READ_BYTES);
  28.          // try reading it
  29.          NumBytes := aProcess.Output.Read((MemStream.Memory + BytesRead)^, READ_BYTES);
  30.          if NumBytes > 0 // All read() calls will block, except the final one.
  31.             then Inc(BytesRead, NumBytes)
  32.          else
  33.             BREAK // Program has finished execution.
  34.        end;
  35.        MemStream.SetSize(BytesRead);
  36.        Lines.LoadFromStream(MemStream);
  37.        Memo1.lines.AddStrings(Lines);
  38.        aProcess.Free;
  39.        Lines.Free;
  40.        MemStream.Free;
  41.     end;      

Friendly, JP
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

makgab

  • Jr. Member
  • **
  • Posts: 55
Re: QR code reading with cam
« Reply #7 on: March 09, 2016, 06:33:54 am »
Thanks! the opencv camera capture works. I need to solve the qr code recognize.
I use the zbarimg as you showed it. :)

But I would like to recognize the qr code with nice solution (without any external app). (ZXingDelphi using?)
« Last Edit: March 09, 2016, 11:54:10 am by makgab »

makgab

  • Jr. Member
  • **
  • Posts: 55
Re: QR code reading with cam
« Reply #8 on: March 09, 2016, 09:50:33 am »
I found the ZXing for Lazarus: https://github.com/MichaelDemidov/DelphiZXingQRCodeEx

The sample works.But does it has encoding function only?
How can I decode a string from an image (TImage)?

The LazBarcode is very good too! Bit it can generate QR Code. :(  It cannot read/scan QR Code...
« Last Edit: March 09, 2016, 11:04:59 am by makgab »

LacaK

  • Hero Member
  • *****
  • Posts: 703
Re: QR code reading with cam
« Reply #9 on: March 09, 2016, 11:36:23 am »
IIRC there are any C libraries ...
May be do pascal port will be not so complicated (I did port of QRencode library, but it is encode only solution)
But I am not sure if there will not be needed any preprocesing of image.
(remove noise etc.)

makgab

  • Jr. Member
  • **
  • Posts: 55
Re: QR code reading with cam
« Reply #10 on: March 09, 2016, 11:52:38 am »
I don't know the QR code structure. So it is not easy for me. :(

makgab

  • Jr. Member
  • **
  • Posts: 55
Re: QR code reading with cam
« Reply #11 on: March 09, 2016, 01:27:20 pm »
I found the port of zbarimg: http://blog.freehand.com.ua/2013/03/zbar-reading-bar-codes-in-delphi.html
Original source: http://www.freehand.com.ua/Projects/ZBar/Project.zip

I tried to compile it under Lazarus (win32) and it was success, but at run time it has access violation at line:
zbarimg_.lpr:
Quote
    processor := zbar_processor_create(0);

What is wrong?

(Lazarus source is attached. The dlls are near zbarimg_.exe locally.)

« Last Edit: March 09, 2016, 01:30:31 pm by makgab »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: QR code reading with cam
« Reply #12 on: March 10, 2016, 03:23:11 am »
hello,
you need to add mode delphi directive in your source code because it come from delphi

in the zbarimg_.lpr file :
Code: Pascal  [Select][+][-]
  1. program zbarimg_;
  2. {$mode delphi}{$H+}
  3. {$APPTYPE CONSOLE}
  4. {$R *.res}
  5. uses
  6.   SysUtils,
  7.   ZBar in 'lib/ZBar.pas',
  8. //  magick_wand in 'lib/ImageMagick/wand/magick_wand.pas', magick wand and imagemagick units
  9. //  ImageMagick in 'lib/ImageMagick/magick/ImageMagick.pas'; are included in lazarus
  10.     magick_wand,ImageMagick;    

in the zbar.pas file :
Code: Pascal  [Select][+][-]
  1. unit zbar;
  2. {$mode delphi}{$H+}
  3. interface
  4. {$MINENUMSIZE 4}
  5. uses
  6.   Windows, SysUtils, Classes {, dbc, DLL96V1, DLLSP96};  

you need to have also imagemagick and libzbar installed in your system or put all the dll of those libraries in your project folder (see zbar_files attachment)

with the qr_code_example , i get qr_code_result (see attachments)

OK with Lazarus 1.6 Windows 32 bits  , Libzbar 0.10 , ImageMagick 6.9.3-7-Q8-x86

there is a bug to be corrected :  image is scanned twice.

Friendly, J.P
« Last Edit: March 10, 2016, 03:45:12 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

makgab

  • Jr. Member
  • **
  • Posts: 55
Re: QR code reading with cam
« Reply #13 on: March 10, 2016, 09:41:58 am »
I have still same error: acces violation...  >:(
I downloaded it: http://www.imagemagick.org/download/binaries/ImageMagick-6.9.3-7-Q8-x86-dll.exe
...and installed it and copy the dlls to project folder.
I modified the zbarimg_.lpr and zbar.pas files.

Do you take a look at my attached files?

jma_sp

  • Full Member
  • ***
  • Posts: 154
  • El conocimiento si ocupa lugar.
Devuan Beowulf 3.0( JWM/ROX/iDesk) - Puppy Linux,  Haiku OS,.ReactOS 0.4.xx  - FreeDos .

 

TinyPortal © 2005-2018