Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import cv2
- import time
- import serial
- from pyzbar.pyzbar import decode
- from datetime import datetime
- carro = {
- "num" : "",
- "entrada": "",
- "saida": "",
- "cartao":""
- }
- estadosCartao = {
- "Done",
- "Invalid"
- }
- class carro:
- def __init__(self, tag_in):
- self.tag = tag_in
- self.entrada = 0
- self.saida = 0
- self.cartao = ""
- def register(self,timein):
- if self.entrada != 0 and self.saida == 0:
- self.saida = timein
- self.calcularCusto()
- time.sleep(2)
- if self.consultarcartao():
- ser.write(b"S")
- else:
- ser.write(b'\b')
- ser.write(b"Cartao Invalido\n")
- else:
- self.entrada = timein
- ser.write(b"E")
- self.saida = 0
- self.cartao = ""
- def calcularCusto(self):
- tempo = int(self.saida - self.entrada)
- print("Tempo decorrido:" , tempo , "Valor :", tempo*0.25)
- ser.write(b'\b')
- ser.write(str("T:"+ str(tempo) + " R$:" + str(tempo/4)).encode())
- ser.write(b"\n")
- def consultarcartao(self):
- if self.tag == "car1":
- self.cartao = "Invalid"
- return 0
- else:
- self.cartao = "Done"
- return 1
- def print(self):
- print(self.tag,":", self.entrada,"-",self.saida," ",self.cartao)
- def getcar(carvect, cartag):
- for i in range(len(carvect)):
- #print(carvect[i].tag,cartag,"comp:",carvect[i].tag== cartag)
- if carvect[i].tag == cartag:
- return i
- newcar = carro(cartag)
- carvect.append(newcar)
- return (len(carvect)-1)
- # img = cv2.imread('1.png')
- cap = cv2.VideoCapture(0)
- cap.set(3, 640)
- cap.set(4, 480)
- carros = []
- notcon = True
- ser = 0
- while notcon:
- try:
- ser = serial.Serial("COM5", 115200)
- notcon = False
- except:
- print("Not connected")
- time.sleep(1)
- while True:
- success, img = cap.read()
- rst = ""
- for barcode in decode(img):
- myData = barcode.data.decode('utf-8')
- pts = np.array([barcode.polygon], np.int32)
- pts = pts.reshape((-1, 1, 2))
- cv2.polylines(img, [pts], True, (255, 0, 255), 5)
- pts2 = barcode.rect
- cv2.putText(img, myData, (pts2[0], pts2[1]), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (255, 0, 255), 2)
- rst = myData
- if rst != "":
- c = getcar(carros,rst)
- carros[c]
- carros[c].register(time.time())
- carros[c].print()
- rst = ""
- time.sleep(1)
- cv2.imshow('Result', img)
- cv2.waitKey(1)
- #print("mydata é: ",decode(img))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement