champ1
Posts: 70
Joined: Tue Jul 17, 2018 12:36 am

camera-based barcode reader

Thu Oct 25, 2018 10:05 am

I'm thinking to interface camera with raspberry pi3 to scan barcode. I have never done this type of work before, can some one advice with some points

1. if I use good quality of camera at what speed it can scan the barcode ?
2. I am looking for industrial use, would PI work continuously ?

I'm afraid that it should not be hung ?

User avatar
RaTTuS
Posts: 10242
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: camera-based barcode reader

Thu Oct 25, 2018 10:13 am

1) https://technoobsite.wordpress.com/2016 ... e-scanner/ may help = this was a quick google for the problem dunno know anything more about it
2) yes
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

gordon77
Posts: 3889
Joined: Sun Aug 05, 2012 3:12 pm

Re: camera-based barcode reader

Thu Oct 25, 2018 11:06 am

you could try zbar

sudo apt-get install zbar-tools

a bit of example code using the Pi camera, raspistill and python.

Code: Select all

import os, subprocess, sys, time

if os.path.exists('out.txt'):
   os.remove('out.txt')
   
rpistr = "raspistill -t 1000 -o image.jpg && zbarimg image.jpg >> out.txt"

p = subprocess.Popen(rpistr, shell=True, preexec_fn=os.setsid)
time.sleep(5)
if os.path.exists('out.txt'):
   with open("out.txt", "r") as file:
      inputx = file.readline()
   print (inputx)

champ1
Posts: 70
Joined: Tue Jul 17, 2018 12:36 am

Re: camera-based barcode reader

Sat Oct 27, 2018 9:18 am

RaTTuS wrote:
Thu Oct 25, 2018 10:13 am
1) https://technoobsite.wordpress.com/2016 ... e-scanner/ may help = this was a quick google for the problem dunno know anything more about it
2) yes
Thanks RaTTuS I have both Pi3 and Pi camera

I have question, how many invoice pi camera scan in one minute ?

Does scanning speed depend on camera or Pi3 or on the both Camera and Pi3 ?

champ1
Posts: 70
Joined: Tue Jul 17, 2018 12:36 am

Re: camera-based barcode reader

Sat Oct 27, 2018 9:21 am

gordon77 wrote:
Thu Oct 25, 2018 11:06 am
you could try zbar

sudo apt-get install zbar-tools

a bit of example code using the Pi camera, raspistill and python.
Nice gordon77 I'm still making plan I haven't decided programming language. I'll come to this point later

halajamal
Posts: 42
Joined: Wed Sep 26, 2018 11:36 am

Re: camera-based barcode reader

Sat Mar 16, 2019 6:01 pm

gordon77 wrote:
Thu Oct 25, 2018 11:06 am
you could try zbar

sudo apt-get install zbar-tools

a bit of example code using the Pi camera, raspistill and python.

Code: Select all

import os, subprocess, sys, time

if os.path.exists('out.txt'):
   os.remove('out.txt')
   
rpistr = "raspistill -t 1000 -o image.jpg && zbarimg image.jpg >> out.txt"

p = subprocess.Popen(rpistr, shell=True, preexec_fn=os.setsid)
time.sleep(5)
if os.path.exists('out.txt'):
   with open("out.txt", "r") as file:
      inputx = file.readline()
   print (inputx)


hello I did that code
it is only return scanned or not
but didn't return the value of the qr code

gordon77
Posts: 3889
Joined: Sun Aug 05, 2012 3:12 pm

Re: camera-based barcode reader

Sun Mar 17, 2019 10:46 am

try this.. based on https://www.pyimagesearch.com/2018/05/2 ... with-zbar/

install pyzbar

sudo pip3 install pyzbar

and opencv..

sudo pip3 install opencv-python
sudo apt-get install libcblas-dev
sudo apt-get install libhdf5-dev
sudo apt-get install libhdf5-serial-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libjasper-dev
sudo apt-get install libqtgui4
sudo apt-get install libqt4-test

Code: Select all

#!/usr/bin/python3
# import the necessary packages
from pyzbar import pyzbar
import argparse
import cv2
import os,sys
import picamera
import time

# initialise pi camera
if os.path.exists('/dev/video0') == False:
  path = 'sudo modprobe bcm2835-v4l2 '
  os.system (path)
  time.sleep(1)

cv2.namedWindow('Frame')
vs = cv2.VideoCapture(0)
vs.set(3, 1024)
vs.set(4, 768)
time.sleep(1.0)

while True:
   ok, image = vs.read()
# loop over the detected barcodes
   barcodes = pyzbar.decode(image)
   print (barcodes)
   for barcode in barcodes:
	# extract the bounding box location of the barcode and draw the
	# bounding box surrounding the barcode on the image
      (x, y, w, h) = barcode.rect
      cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
 
	# the barcode data is a bytes object so if we want to draw it on
	# our output image we need to convert it to a string first
      barcodeData = barcode.data.decode("utf-8")
      barcodeType = barcode.type
 
	# draw the barcode data and barcode type on the image
      text = "{} ({})".format(barcodeData, barcodeType)
      cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,0.5, (0, 0, 255), 2)
 
	# print the barcode type and data to the terminal
      print("[INFO] Found {} barcode: {}".format(barcodeType, barcodeData))
 
# show the output image
   cv2.imshow("Image", image)
   cv2.waitKey(10)

Return to “Beginners”