def see(polly,camera): camera.capture(filename) camera.close() topn = inception_predict.predict_from_local_file(filename, N=5) print topn top1 = topn[0] # Convert probability to integer percentage prob = (str)((int)(top1[0]*100)) # Remove category number item = top1[1].split(' ') item = ' '.join(item[1:]) message = "I'm "+prob+"% sure that this is a "+item+". " return message
return ''.join(random.choice(string.lowercase) for i in range(length)) #while True: # Create unique image name uniqueid = 'mxnet_uuid_{0}_{1}'.format(randomword(3),strftime("%Y%m%d%H%M%S",gmtime())) ret, frame = cap.read() imgdir = 'images/' filename = 'tx1_image_{0}_{1}.jpg'.format(randomword(3),strftime("%Y%m%d%H%M%S",gmtime())) cv2.imwrite(imgdir + filename, frame) # Run inception prediction on image try: topn = inception_predict.predict_from_local_file(imgdir + filename, N=5) except: errorcondition = "true" # CPU Temp f = open("/sys/devices/virtual/thermal/thermal_zone1/temp","r") cputemp = str( f.readline() ) cputemp = cputemp.replace('\n','') cputemp = cputemp.strip() cputemp = str(round(float(cputemp)) / 1000) cputempf = str(round(9.0/5.0 * float(cputemp) + 32)) f.close() # GPU Temp f = open("/sys/devices/virtual/thermal/thermal_zone2/temp","r") gputemp = str( f.readline() )
#filename = '/home/pi/cap.jpg' filename = '/tmp/cap.jpg' # camera.start_preview() # camera.capture(filename) cv2.imwrite(filename, image) vidcap.release() # camera.stop_preview() fin = open(filename, 'rb') encoded_image_bytes = fin.read() fin.close() logging.info("Finalizando o processamento de imagem") logging.info("Iniciando o inception_predict") topn = inception_predict.predict_from_local_file(filename, N=2) logging.info("Finalizando o inception_predict") # MQTT settings logging.info("Iniciando a insercao do label no MQTT") topicname = 'recyclesorter/demo-' + str(datetime.now().strftime("%Y-%m-%d-%H")) deviceid = random.choice(deviceids) datetimenow = str(datetime.now()) myAWSIoTMQTTClient.connect() horizonalpin = 15 vertizalpin = 12 recylefound = 0 logging.info("Finalizando a insercao do label no MQTT")
#if not use_motion_capture: camera = picamera.PiCamera() while True: if use_motion_capture: if (GPIO.input(motion_sensor_pin)): print('Motion detected at ', timestamp()) # with picamera.PiCamera() as camera: # camera.resolution = (1024, 1024) time.sleep(2) t = timestamp() fname = image_directory + t + '.jpg' camera.capture(fname) print('saved image', fname) topn, predstr = inception_predict.predict_from_local_file(fname, N=5) print(predstr) with open(prediction_directory + t + '.json', 'wa') as f: json.dump(predstr, f) else: # Take the jpg image from camera print("Capturing") filename = '/home/pi/cap.jpg' # Show quick preview of what's being captured camera.start_preview() camera.capture(filename) camera.stop_preview() # Run inception prediction on image print("Predicting")