def get_image(monitor): """ Retrieves the image for the defined monitor. :param monitor: the monitor :type monitor: str """ global config, monitors, recent_images ts = datetime.now() filename = ts.strftime(config['general']['timestamp']) # paused? out_dir = monitors[monitor]['output'] out_file = out_dir + os.sep + filename try: if not os.path.exists(out_dir + os.sep + "PAUSED"): urllib.urlretrieve(monitors[monitor]['url'], out_file) recent_images[monitor].insert(0, out_file) recent_images[monitor] = recent_images[monitor][:2] # detect motion? if monitors[monitor]['detect_motion'] and (len(recent_images[monitor]) == 2): ratio, detected = motion.detect_motion( recent_images[monitor][0], recent_images[monitor][1], monitors[monitor]['threshold']) # delete old file? if not detected: os.remove(recent_images[monitor][1]) except Exception, e: print(e)
while(True): #Capacity Detection fullCapacity = 63 #25 inches ~ 63.5 cm ultrasonicValue = detect_capacity(inputTrigger, inputEcho) #Get distance from closest trash pile distance = fullCapacity - ultrasonicValue #Compute the capacity capacity = (((fullCapacity - distance)/fullCapacity) * 100) #Put the capacity value in the API putdata("capacity", capacity) #Object Detection motion = detect_motion(inputMotion) if (motion == True): print("Motion detected") #Turn on the LED strip GPIO.output(inputLED, True) #Configure the lid GPIO.output(inputLid, True) #Lid opens time.sleep(2) GPIO.output(inputLid, False) #Lid closes #Take picture capture() #Turn of LED strip
if(new_data[i]==chr(255) and new_data[i+1]==chr(217)): #Record the last byte address of this chunk end_write=i+2 #Record that we are no longer in a file in_file=False #Perform our final write f.write(new_data[start_write:end_write]) #Record that we are done writing to this file file_write==False #Close the file f.close() #if not the first image then look for motion if (first_image==False): # difference = motion.compare(filename, prior_filename) # print "Hue Variation : " , int(difference) motion_level = motion.detect_motion(prior_filename, filename, settings.rgb_threshold, settings.rgb_blocksize, settings.rgb_outline, settings.rgb_outline_color) os.remove(prior_filename) print "Motion Level :", int(motion_level) if motion_level > settings.threshold: shutil.copy(filename, "motion/") if settings.rgb_outline: shutil.copy(filename + ".outlined.jpg", "motion.outlined/") os.remove(filename + ".outlined.jpg") #record the filename of the image we just created as the prior image prior_filename=filename #Record we are no longer after the first iamge first_image=False else: