It is currently Tue Feb 25, 2020 12:46 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: ZBAR examples
PostPosted: Sat Apr 06, 2019 3:19 am 
Offline
Enthusiast
Enthusiast

Joined: Sun Jun 15, 2008 3:13 am
Posts: 237
Location: Russia
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)?


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Sat Apr 06, 2019 9:27 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4520
Location: Germany
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Sat Apr 06, 2019 9:45 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4520
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Sun Apr 07, 2019 3:37 am 
Offline
Enthusiast
Enthusiast

Joined: Sun Jun 15, 2008 3:13 am
Posts: 237
Location: Russia
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:
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:
[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!


Top
 Profile  
Reply with quote  
 Post subject: Re: ZBAR examples
PostPosted: Sun Apr 07, 2019 2:12 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 4520
Location: Germany
Hi,

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

Code:
Structure zbar_image_s; Align #PB_Structure_AlignC
  format.l            ; fourcc image format code
  width.l
  height.l        ; image size
  *data           ; image sample data
  datalen.l       ; allocated/mapped size of data
  *userdata       ; user specified data associated w/image
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    crop_x.l
    crop_y.l
    crop_w.l
    crop_h.l
  CompilerEndIf
  cleanup.zbar_image_cleanup_handler        ; cleanup handler
  refcnt.l                                  ; reference count
  *src                                      ; originator
  srcidx.l                                  ; index used by originator
  *next                                     ; internal image lists
  seq.l                                     ; page/frame sequence number
  *syms.zbar_symbol_set_s                   ; decoded result set
EndStructure


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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye