Skip to content

Instantly share code, notes, and snippets.

@rodgomesc
Created November 28, 2014 18:17
Show Gist options
  • Save rodgomesc/abbc6462107685909984 to your computer and use it in GitHub Desktop.
Save rodgomesc/abbc6462107685909984 to your computer and use it in GitHub Desktop.
barcodeDetect
import time
import csv
from SimpleCV import Color, ColorCurve, Camera, Image, pg, np, cv
from SimpleCV.Display import Display
cam = Camera(0)
display = Display((800,600))
data = "None"
mydict = dict()
myfile = "barcode-list.csv"
while display.isNotDone():
display.checkEvents()#Checar por clicks do mouse
img = cam.getImage()
img.drawRectangle(img.width/4,img.height/4,img.width/2,img.height/2,color=Color.RED,width=3)
if display.mouseLeft: # click com mouse para leitura
img.drawText("Lendo codigo de barras... Aguarde",10,70,fontsize=20)
img.save(display)
barcode = img.findBarcode()
if barcode: # se existir um codigo de barras!
data = str(barcode[0].data) # lembrando que tem que mostrar o indice 0 da lista
print data
if mydict.has_key(data):
mydict[data] = mydict[data] + 1
else:
mydict[data] = 1
img.drawText("Click para escanear.",10,10,color=Color.RED,fontsize=30)
myItem = "Ultimo item escaneado: " + data
img.drawText(myItem,10,30,fontsize=30)
img.save(display) #display
#Grava em um arquivo cvs
target= open( myfile, "wb" )
wtr= csv.writer( target )
wtr.writerow( ["item","count"])
for d in mydict.items():
wtr.writerow(d)
target.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment