ZBAR examples

Just starting out? Need help? Post your questions and find answers here.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: ZBAR examples

Post by AAT »

infratec, thank you very much for sharing your wrapper!
Can you give an example how to use zbar with webcam directly (without saving picture to file)?
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ZBAR examples

Post by infratec »

HI,

sorry for the delay, but my code was not running in win10.
After a hour of searching I found out that libzbar-0.dll was the fault.
I downloaded then:

https://sourceforge.net/projects/zbarw/ ... p/download

and it worked.

Code: Select all

EnableExplicit


IncludeFile "ZBar.pbi"


ProcedureC data_handler(*img, *userdata)
  
  Protected *sym, type.i, *data
  
  
  Debug "data_handler"
  
  *sym = zbar_image_first_symbol(*img)
  
  While *sym
    If zbar_symbol_get_count(*sym)
      Continue
    EndIf
    
    type = zbar_symbol_get_type(*sym)
    If type = #ZBAR_PARTIAL
      Continue
    EndIf
    
    Debug zbar_symbol_get_data(*sym)
    Debug zbar_get_symbol_name(type)
    
    *sym = zbar_symbol_next(*sym)
  Wend
  
EndProcedure



Define.l infmt, outfmt, display, active, rc
Define.i Result

Define *proc
Define video_device$



If ZBar_Init()
  
  *proc = zbar_processor_create(1)
  If *proc
    zbar_processor_set_data_handler(*proc, @data_handler(), #Null)
    
    video_device$ = ""
    infmt = 0
    outfmt = 0
    display = #True
    
    
    zbar_processor_request_size(*proc, 640, 480)
    
    If infmt Or outfmt
      zbar_processor_force_format(*proc, infmt, outfmt)
    EndIf
    
    
    If zbar_processor_init(*proc, @video_device$, display) Or (display And zbar_processor_set_visible(*proc, #True))
      Result = zbar_processor_error_spew(*proc, 0)
      Debug "zbar_processor_init : " + Str(Result)
      End Result
    EndIf

    ; start video
    active = #True
    If zbar_processor_set_active(*proc, active)
      Result = zbar_processor_error_spew(*proc, 0)
      Debug "zbar_processor_set_active" + Str(Result)
      End Result
    EndIf
    
    ; let the callback handle Data
    Repeat
      rc = zbar_processor_user_wait(*proc, -1)
      
      Debug rc
      
      If rc = 'q' Or rc = 'Q'
        Break
      EndIf
      
      If rc = ' '
        If active
          active = #False
        Else
          active = #True
        EndIf
        
        If zbar_processor_set_active(*proc, active)
          Result = zbar_processor_error_spew(*proc, 0)
          Debug "zbar_processor_set_active" + Str(Result)
          End Result
        EndIf
      EndIf
    Until rc >= 0
    
    If rc <> 0 And rc <> 'q' And rc <> 'Q' And zbar_processor_get_error_code(*proc) <> #ZBAR_ERR_CLOSED
      Result = zbar_processor_error_spew(*proc, 0)
      Debug Result
      End Result
    EndIf

    ; free resources (leak check)
    zbar_processor_destroy(*proc)
    
  Else
    Debug "ERROR: unable to allocate memory?"
  EndIf
  
EndIf
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ZBAR examples

Post by infratec »

Else you can use any methode to get a picture into RAM and convert it to a form which zbar understand.
Look at the example with the loaded file :wink:

I used escapi3 for things like this.
AAT
Enthusiast
Enthusiast
Posts: 259
Joined: Sun Jun 15, 2008 3:13 am
Location: Russia

Re: ZBAR examples

Post by AAT »

Hi, infratec!
Your examples are interesting and very useful especially to get started with zbar!
But I think it will take quite a long time to get a really working program. :wink:

There are some troubles with zbar:
1. video freezes often:

Code: Select all

ProcedureC data_handler(*img, *userdata)
...
   While *sym
    If zbar_symbol_get_count(*sym) ; <------freezes here!
      Continue
    EndIf
 ...
  Wend
 
EndProcedure
2. after updating libraries to version 20121031 an error appeared in OwnCleanUp(*image.zbar_image_s) during executing:

Code: Select all

[ERROR] The specified '*MemoryID' is not valid.
I think it's needed to update the functions prototypes for libraries v. 20121031

But these are the details... Thanks again for the great work!
Good luck!
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ZBAR examples

Post by infratec »

Hi,

this windows version use a newer structure, but does not increase the version to 0.11 :!:


I updated the listing on the fisrt page

If you add the crop stuff, the IMA with OwnCleanup() is fixed.

With my webcam (Microsoft VX-6000) I get no freezes.
So I can not help you.
Last edited by infratec on Wed Nov 11, 2020 10:24 am, edited 1 time in total.
loulou2522
Enthusiast
Enthusiast
Posts: 551
Joined: Tue Oct 14, 2014 12:09 pm

Re: ZBAR examples

Post by loulou2522 »

Hi Infratec,
I download the dll libzbar-0.dll from https://sourceforge.net/projects/zbarw/ ... p/download like you mentionned in your post and try to use ypur wrapper. Unfortunetly the l libzbar-0.dll won't want to load ?
Have you an idea ?
Thanks in advance


I am on windows 10 with the last version on Purebasic 5.73 beta 4
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ZBAR examples

Post by infratec »

This is a x86 dll.
Did you use PB x86 ?

As written you need also libiconv-2.dll.
Is it in the same directory?

Btw. From where you downloaded beta 4 :?:
I only know beta 3
loulou2522
Enthusiast
Enthusiast
Posts: 551
Joined: Tue Oct 14, 2014 12:09 pm

Re: ZBAR examples

Post by loulou2522 »

[quote="infratec"]This is a x86 dll.
Did you use PB x86 ? Yes

As written you need also libiconv-2.dll.
Is it in the same directory? Yes

Btw. From where you downloaded beta 4 ?: I only know beta 3 Sorry i use PB 5.73 beta 3

I try to FreeMemory(*image\Data)
launch with n older version of PB (PB 5.72) It works but i have an error on following lines

Code: Select all

Ligne 947   FreeMemory(*image\Data)  l'argument *MemoryId spécifié n'est pas valide
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ZBAR examples

Post by infratec »

Do you use the fix from above?

Code: Select all

Structure zbar_image_s
I will try it today with 5.73b3
loulou2522
Enthusiast
Enthusiast
Posts: 551
Joined: Tue Oct 14, 2014 12:09 pm

Re: ZBAR examples

Post by loulou2522 »

infratec wrote:Do you use the fix from above?

Code: Select all

Structure zbar_image_s
I will try it today with 5.73b3
Result finally I put the new structure in my programm and execute it . It works wel. With PB 6.75 beta 3 the problem is always the same.
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: ZBAR examples

Post by Jac de Lad »

loulou2522 wrote:PB 6.75 beta 3
Wow, you're the first time traveller I've met! I love such typos...
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ZBAR examples

Post by infratec »

I just tested it with PB 5.73 beta 3 x86 on Windows 10 x64:

I had to comment in the Align #PB_Structure_AlignC at the Structure zbar_image_s

I copied my complete file to my post on page 1.
Please copy the complete file as new zbar.pbi.
Oliver13
User
User
Posts: 90
Joined: Thu Sep 30, 2010 6:40 am

Re: ZBAR examples

Post by Oliver13 »

@infratec, thank you very much for the include and sample.
Selecting a video source and taking a qr code by camera works well.

Could you please help with the following further questions, too ?

- when user closes scan window, the zbar_processor_user_wait seems still to be active
If I change line 82 to

Code: Select all

If rc = 'q' Or rc = 'Q' Or rc=-1
the loop will be leaved, but then an IMA occurs

- is there a way to retrieve the available videosources ? This would allow to pass video_device$ to zbar_processor_init() in order to avoid the user needing to select the camera every time again

- is there a way to enable the green/red detection rectangles (as shown in zbarcam.exe), when a barcode is detected ?

Thank you and kind regards
Oli
infratec
Always Here
Always Here
Posts: 7620
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ZBAR examples

Post by infratec »

Hi Oliver,

my zbar stuff is now nearly 4 years old and I don't use it since years, since I use now an other tool to decode QRCode.
I just tried to run my code with PB 6.11 and it is not runing.
At the moment I have no time to deep dive into zbar stuff.

But I think there are some C examples available which shows how this can be achieved.
Post Reply