Ejemplo n.º 1
0
def main():
    trash_filename = "trash.jpg"
    try:
        cam = initCamera()
        while True:
            """
            """
            score = 0
            for i in range(5):
                takePhoto(cam, trash_filename)
                data = (post_imageV2("TrashIdentifier_968106762", trash_filename, ibm_auth))
                print(data['images'][0]['classifiers'][0]['classes'][0]['score'])
                score += (data['images'][0]['classifiers'][0]['classes'][0]['score'])
            
            score /= 5
            print(score)

            if score > 0.20:
                print("Is trash")
                sendSMS("Garbage can is full!!!!", "+16465411524")
                time.sleep(2)

            else:
                print("Not trash")

    except KeyboardInterrupt:
        print("Quitting Application")
Ejemplo n.º 2
0
def trainWatson():

    names = ["empty", "full"]

    cam = initCamera()

    for i in range(2):

        if not os.path.exists(names[i]):
            os.makedirs(names[i])

        for j in range(50):
            takePhoto(cam, names[i] + '/' + names[i] + str(j) + ".jpg")
            print("CLICK")
            time.sleep(.3)


        zipf = zipfile.ZipFile(names[i] + ".zip", 'w', zipfile.ZIP_DEFLATED)
        zipdir(names[i], zipf)
        zipf.close()

        if i == 0:
            confirmation = input("Read to proceed with full?: ")

            while confirmation != "yes":
                confirmation = input("Read to proceed with full?: ")

    with open(join(dirname(__file__), 'full.zip'), 'rb') as full, \
        open(join(dirname(__file__), 'empty.zip'), 'rb') as empty:
      
        visual_recognition = VisualRecognitionV3('2016-05-20', api_key=ibm_auth)
        with open('class.py', 'w') as outfile:
            data = visual_recognition.create_classifier('TrashIdentifier', _positive_examples=full, negative_examples=empty)
            json.dump(data, outfile, indent=2)
Ejemplo n.º 3
0
def getSamplePhotos():
    print('Getting unknown faces...')
    for i in range(5):
        fileName = '../bin/unknownFaces/sample0.jpg'
        camera.takePhoto(fileName)
        unknownPicture.append(face_recognition.load_image_file(fileName))
        unknownFace.append(
            face_recognition.face_encodings(unknownPicture[i])[0])
Ejemplo n.º 4
0
 def send_Text_Mail(self, To_Add, Subject, txtMessage):
     Mail_Body = self.initialise_Mail_Body(To_Add, Subject)
     #Attach Mail Message
     Mail_Msg = MIMEText(txtMessage, 'plain')
     Mail_Body.attach(Mail_Msg)
     #TODO
     part = MIMEBase('application', "octet-stream")
     # take photo and attach
     takePhoto()
     part.set_payload(open("../camera/photo.jpg", "rb").read()) # check the path !!!!!!!!
     Encoders.encode_base64(part)
     part.add_header('Content-Disposition', 'attachment; filename="photo.jpg"')
     Mail_Body.attach(part)
     #Send Mail
     self.session.sendmail(FROM_ADD, [To_Add], Mail_Body.as_string())
Ejemplo n.º 5
0
import camera
import time
count = 33

while True:
	nothing = raw_input("picture time")
	camera.takePhoto("img/bottles/bottle%d.jpg" % (count))
	count = count + 1
Ejemplo n.º 6
0
def mqtt(data):

    try:
        takePhoto()
    except Exception as e:
        print("type error: " + str(e) + " problem with camera!")

    keys = [
        "ID", "STA", "SHA", "SLA", "STS1", "STS2", "STS3", "SHS1", "SHS2",
        "SHS3", "SPL", "SPR", "SVB"
    ]
    values = re.split("\s+", data)
    values = [x for x in values if x]  # remove null items
    new_dict = dict(zip(keys, values))
    new_dict["TIME"] = str(datetime.now())
    print("received message =", new_dict)
    topic = "LISIMETRO"
    print("TOPIC: ", topic)
    data = {
        "ID": new_dict["ID"],
        "TIME": new_dict["TIME"],
        "SVB": new_dict["SVB"],
        "STA": new_dict["STA"],
        "SHA": new_dict["SHA"],
        "SLA": new_dict["SLA"],
        "SPL": new_dict["SPL"],
        "SPR": new_dict["SPR"],
        "STS1": new_dict["STS1"],
        "STS2": new_dict["STS2"],
        "STS3": new_dict["STS3"],
        "SHS1": new_dict["SHS1"],
        "SHS2": new_dict["SHS2"],
        "SHS3": new_dict["SHS3"]
    }
    # data = {
    #     "ID": new_dict["ID"],
    #     "TIME": new_dict["TIME"],
    #     "SVB": new_dict["SVB"][2] + "." + new_dict["SVB"][3:],
    #     "STA": new_dict["STA"][2] + "." + new_dict["SVB"][3:],
    #     "SHA": new_dict["SHA"][3:4] + "." + new_dict["SVB"][5:],
    #     "SLA": new_dict["SLA"][2:],
    #     "SPL": new_dict["SPL"][1:2] + "." + new_dict["SVB"][3:],
    #     "SPR": new_dict["SPR"][2] + "." + new_dict["SVB"][3:],
    #     "STS1": new_dict["STS1"][3:4] + "." + new_dict["SVB"][5:],
    #     "STS2": new_dict["STS2"][2:3] + "." + new_dict["SVB"][4:],
    #     "STS3": new_dict["STS3"][2:3] + "." + new_dict["SVB"][4:],
    #     "SHS1": new_dict["SHS1"][2:3] + "." + new_dict["SVB"][4:],
    #     "SHS2": new_dict["SHS2"][2:3] + "." + new_dict["SVB"][4:],
    #     "SHS3": new_dict["SHS3"][2:3] + "." + new_dict["SVB"][4:]
    # }

    data = json.dumps(data, ensure_ascii=True)
    print("JSON DUMP =", data)
    #broker = "94.62.172.88"
    broker = "ietsis.dynu.net"
    # reading is a string...do whatever you want from here
    client = paho.Client("client-001")
    print("connecting to broker ", broker)
    client.connect(broker, 1883, 60)  # connect
    client.loop_start()  # start loop to process received messages
    client.subscribe(topic)  # subscribe
    client.publish(topic, data)  # publish
    time.sleep(4)
    client.disconnect()  # disconnect
    client.loop_stop()  # stop loop
    print('prepare shutdown')
    os.system("sudo shutdown now -r")
Ejemplo n.º 7
0
)

args = parser.parse_args()

if __name__ == '__main__':
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        addr = (args.ip, args.port)
        logging.info("Server listening on: %s:%d" % (args.ip, args.port))
        sock.bind(addr)
        sock.listen(1)
        while True:
            logging.info("Received connection")
            conn, client = sock.accept()
            try:
                takePhoto()
                f = open('cameraTest.jpg','rb')
                while True:
                    msg = f.read(1024)
                    if not msg:
                        logging.info("Image sent")
                        break
                    conn.send(msg)
            finally:
                conn.close()
                f.close()
    finally:
        sock.close()


Ejemplo n.º 8
0
import camera
import time

personName = input('Please type your name: ')

for i in range(1, 6):
    time.sleep(1)
    print('Here\'s for photo', i, 'of 5:')
    time.sleep(2)

    # Countdown
    print('3')
    time.sleep(1)
    print('2')
    time.sleep(1)
    print('1')
    time.sleep(1)
    
    print('Taking Photo...\n')
    fileName = '../bin/knownFaces/' + personName + str(i) + '.jpg'
    camera.takePhoto(fileName)
    
print("\nAll done! Your face will now be recognized.")
Ejemplo n.º 9
0
    stamp = '%d-%02d-%02d-%02d%02d%02d' % (t.tm_year, t.tm_mon, t.tm_mday,
                                           t.tm_hour, t.tm_min, t.tm_sec)
    return stamp + '.jpg'


files_route = '/home/malu/Documents/bus/'
basePhotoDir = files_route + 'empty.jpg'
prevPhotoDir = files_route + 'prev.jpg'
newPhotoDir = files_route + 'new.jpg'
logPhotoDir = files_route + '/log/'
bufferPhotoDir = files_route + '/fotos/'

timeOfPhoto = timestamp()
print(timeOfPhoto)

camera.takePhoto(newPhotoDir)
prev_thresh = imageAnalizer.getThreshold(basePhotoDir, prevPhotoDir)
new_thresh = imageAnalizer.getThreshold(basePhotoDir, newPhotoDir)
thresh = imageAnalizer.compareDifferenceInGrays(prev_thresh, new_thresh)

erosion = imageAnalizer.erodeImageContorns(thresh)
ratio = imageAnalizer.whitePixelsPercentage(erosion)
print(ratio)

if ratio > 5:
    imageAnalizer.saveImageAs('new.jpg', logPhotoDir + timeOfPhoto)
    imageAnalizer.saveImageAs('new.jpg', 'prev.jpg')

imageAnalizer.saveImageAs(newPhotoDir, bufferPhotoDir + timeOfPhoto)

cv2.imshow('1', thresh)
Ejemplo n.º 10
0
#adds every possible combination of the above filters to codeSamples
def recursiveFunc(text):
    if (not text in codeSamples):
        #print(text)
        codeSamples.append(text)
    for original, corrections in alts.items():
        for i in range(0, text.count(original)):
            for correction in corrections:
                s = nth_repl(text, original, correction, i + 1)
                recursiveFunc(s)


filename = "input.jpg"

#takes photo
takePhoto(filename)

#some initial things pre filter
text = google_vision(filename)
text = " " + text
if (not text[len(text) - 1] == "}"):
    text = text + "}"

recursiveFunc(text)

codeOutput = ""

#tries to run the codeSamples, breaks once one runs
for s in codeSamples:
    if (s.count("{") == s.count("}") and s.count("(") == s.count(")")):
        text_file = open("Output.c", "w")
Ejemplo n.º 11
0
import cmd
import camera
import time


def timestamp():
    t = time.localtime()
    stamp = '%d-%02d-%02d-%02d%02d%02d' % (t.tm_year, t.tm_mon, t.tm_mday,
                                           t.tm_hour, t.tm_min, t.tm_sec)
    return stamp


args = cmd.readArguments()

if args['name'] == 'TIME':
    camera.takePhoto(timestamp())
if args['name'] == 'empty':
    camera.takePhoto('empty')