Ask Your Question

OpenCV & ZBar scanning

asked 2014-04-01 06:55:18 -0500

bilow gravatar image

updated 2014-04-01 07:00:58 -0500


I've found this Tutorial on the web for using OpenCV and ZBar for "xx"-code scanning. I've got this stuff working and it really is a nice clean tut. But now I'm trying to do the same, but now with live camera feed (webcam). I've tried several things to get this working, but I can't seem to get the feed scanned over my webcam feed. Does anyone have any experience with this? Can you share a sample project with me, or refer me to a other sample where I can do this?

Source Tut:

!..To be clear:

  • I want to be able to scan QR-codes using OpenCV.
  • Datamatrix example in OpenCV isn't working for me (3 characters limit?). Found in the sample code. Pls correct me if I'm wrong and can scan more characters with this.
  • I've tried ZBar in this example here, but I also have read about ZXing. Which library to use isn't that important to me. I just want to be able to scan QR with OpenCV. I

Hope someone can help me to the right direction. Thanks in advance,


edit retag flag offensive close merge delete


It is kind of bizarre. If you succeed in executing the code for a single image, then just put that in a seperate function, add a loop to go through video frames one by one and then apply the function to that specific frame. That would do the trick right?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-04-01 07:05:45 -0500 )edit

The code from the sample is using images stored on the computer. I'm trying to loop trough the code frame by frame as you said yes (got the code from the openCV samples), but I'm getting this error:

Unhandled exception at 0x770E4B32 in ConsoleApplicationCV.exe: Microsoft C++ exception: cv::Exception at memory location 0x002FB3F4.

If you'd take the sample given above (see link), what would be the correct way to loop it then??

bilow gravatar imagebilow ( 2014-04-01 07:53:21 -0500 )edit

Just do something like

 VideoCapture capture ("location_to_video");
 Mat current_frame;
    capture >> current_frame;
    if( current_frame.isEmpty() ){break;}
   // apply functionality to your image here!
StevenPuttemans gravatar imageStevenPuttemans ( 2014-04-01 08:10:10 -0500 )edit

And to add to this, your problem is probably a wrong pointer handling. The link you refer to is using the old depricated C api which will dissappear in the near future, so I would suggest switching the code to the C++ interface. Cannot be that hard.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-04-01 08:14:06 -0500 )edit

How about the DataMatrix example given with openCV then? ( Samples -> Cpp -> video_dmtx.cpp ) Why is this only supporting up to 3 characters?

bilow gravatar imagebilow ( 2014-04-01 08:26:26 -0500 )edit

Because it is only a sample ... you should change it to your needs...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-04-01 08:32:16 -0500 )edit

Yeah, I'm reading the code, and checking the source of it over and over (also in objdeteect.hpp). But I can't seem to find where the 3 character limit is set? Or, what would I've to add to make it read 10 characters then (for example).

bilow gravatar imagebilow ( 2014-04-01 08:55:57 -0500 )edit

I do not have time to dig into the code myself ... got my own projects to finish!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-04-02 01:44:07 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-04-02 23:04:33 -0500

ayoungprogrammer gravatar image

Hey bilow, I am the author of the tutorial and I have made a follow up tutorial of bar code / qr code scanning in real time with a webcam:

Hope this helps!

edit flag offensive delete link more


Hi 'youngprogrammer' this example does exactly what I needed. I kept getting errors at the CV_BGR2GRAY conversion, don't know why. Perhaps I had some other things wrong. Enfin, it works now. Thanks for your help and time!

bilow gravatar imagebilow ( 2014-04-03 18:15:13 -0500 )edit

Hi @bilow probably you should add this line

#include <opencv2/opencv.hpp>
Coisadas gravatar imageCoisadas ( 2015-09-06 17:16:07 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2014-04-01 06:55:18 -0500

Seen: 16,184 times

Last updated: Apr 02 '14