Package: barcap
Barcode CaptureIntroductionThis code was made to extract any barcode using your web camera.
As of now it utilizespyzbarandpylibdmtxlibraries. Which have their own set of
recognizable barcodes. Mainly, we were targeting QR codes and data matrix codes. But it will
recognize other popular formats supported by those libraries.Under the hood, this code takes each frame from the camera like soAnd detects barcode if it present.
And finally provides output as a string like sooutput: Wikipedia, the free encyclopediaThere is a probability that algorithm will fail during one of those steps. In such case the code will not
produce any output. Also, there is a small possibility that the algorithm will provide incorrect output. So keep
that in mind while capturing barcodes!RequirementsThis code has been tested on Windows machine. Most likely it will work on alternative OS but we have not
tested it on any other OS.Otherwise, you will need:Python 3OpenCV 2pyzbarpylibdmtxWeb CameraEasy installationUse pip to install this library, fast and easy!!!pipinstallbarcapManual installationInstall librariesOn Linux, you have to install some extra packages:sudoapt-getinstalllibzbar0
sudoapt-getinstalllibdmtx0aOn MAC, that be a little different:brewinstallzbar
brewinstalllibdmtxOn Windows, everything should happen automatically.
If you have any dll problems, please installVisual C++ Redistributable Packages for Visual Studio 2013and see if that resolves those issues.Install python packagesYou can install requirements usingpipinstall-rrequirements.txtFurther instructionshttps://pypi.org/project/pyzbar/https://pypi.org/project/pylibdmtx/Most Basic Barcode CaptureThis is the simplest way to get you started. Also this is the best way to make sure that your setup works properly.
Simply run in a shell:python-mbarcapWindow with your default camera is going to pop up and capture algorithm will be running in a while loop.
If everything is successful you will see output periodically printed out in the shell.Manual CaptureOnce again start while capture loop by running:$ python -m barcapFirst of all, make sure your capture window is selected.
Once, you have a good image in the window with barcode occupying most of the screen press's'key to save this frame.
Openbarcode.jpgand confirm that the frame has been written. Kill the loop by pressing'q'orEsc.If it does not work...Do you have camera connected?Is computer even on?If nothing helps fix your hardware in the software!All jokes aside most likely the libraries do not support this barcode or something wrong with a setup.Final ThoughtsAt this point you probably understand how my routine works so you can try modifying it if things are not working out.Otherwise,Congratulations!!! You got it working!!!Importing Barcode Capture into your own python scriptIf you look closely, you will see that capture loop is insideCaptureProcessclass based onProcessclass
frommultiprocessingmodule.The idea is to run this process and capture frames from a web camera.
Next, those frames will be processed to get desired output.You could use this class to build your own capturing algorithm.
For examples, look closely atbarcode.py,ocr.pyandocr_plus.py.And finally, the user of the capture process would start a process and
get results via shared memory.Here is how you can take advantage of those in your own script.Tocreatea capture instance do following:frombarcap.barcodeimportBarcodeCapturecapture=BarcodeCapture(camera=0)Tostartcapturing process:capture.start()Tostopcapturing process:capture.stop()orcapture.terminate()Tocheckif capturing is still happening:capture.is_alive()Toreaddecoded output:output=capture.ouputprint(f'output:{output}')Tofetchepoch time of the last decoding:importtimeepoch=capture.last_epochtime_stamp=time.strftime('%Y-%m-%d%H:%M:%S',time.localtime(epoch))print(f'last capture:{time_stamp}')You can also check ifnewoutput is availableifcapture.new:print(f'output:{capture.output}')Every time you read output it resets thenewflag.Look closely atmain.pyto get a complete example.Finally,device_list.pyfacilitates in selecting right camera. In case
you might have multiple cameras connected to your computer.Device ListThere is a little device utility that can help you discover connected cameras to the
computer. As of right now the sub package works only on Windows. Also, we decided
that this is optional addition so it won't be compiled by default.In order to compile navigate tosetup.pyscript and uncomment lines for theWindowsDeviceextension. Reinstallbarcapusingsetup.pyscript.Additional Info and QuestionsShoot me email atkirill at kbelyayev.comif you have any questions, suggestions, improvements, additions and etc.
I would love to help you with this script if you hire me as a contractor. I might help you free of charge if
you contribute to this distribution or ask politely. Beer donations are welcome too!Good luck! Happy coding and hacking!