Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import numpy as np, cv2, sys
import memcache
import time
sys.path.append('../../../')
from hsapi import ObjectDetector
from grovepi import *
from twilio.rest import Client
def setType(label):
if(label=="car"):
digitalWrite(car_led,1)
digitalWrite(bus_led,0)
vehicle.set("Prompt",car_msg)
elif(label=="bus"):
digitalWrite(bus_led,1)
digitalWrite(car_led,0)
vehicle.set("Prompt",bus_msg)
else:
digitalWrite(bus_led,0)
digitalWrite(car_led,0)
vehicle.set("Prompt",no_msg)
def sendMsg():
account_sid = "<TWILIO_ACCOUNT_SID>"
auth_token = "<TWILIO_AUTH_TOCEN>"
client = Client(account_sid, auth_token)
message = client.messages.create(to="whatsapp:<DEST_PHONE_NO>",from_="whatsapp:SRC_PHONE_NO",body=vehicle.get("Prompt"))
print(vehicle.get("Prompt"))
print(message.sid)
car_led = 14
bus_led = 15
button = 3
car_msg="There is a car at the toll gate. The toll fee is $5"
bus_msg="There is a bus at the toll gate. The toll fee is $10"
no_msg="There is no vehicle at the toll gate"
pinMode(car_led,"OUTPUT")
pinMode(bus_led,"OUTPUT")
pinMode(button,"INPUT")
net = ObjectDetector(zoom = True, verbose = 2)
video_capture = cv2.VideoCapture(0)
vehicle = memcache.Client(['127.0.0.1:11211'], debug=0)
try:
while True:
_, img = video_capture.read()
result = net.run(img)
if(len(result[1])):
label = net.labels[result[1][0][0]]
print(label)
b_state=digitalRead(button)
time.sleep(.5)
if (b_state == 1):
print("Button pressed")
sendMsg()
setType(label)
img = net.plot(result)
cv2.imshow("Toll Gate", img)
cv2.waitKey(1)
finally:
net.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment