Camera

This application allows the robot to use his camera and take a photo and save it to a specific directory. This app is the base for the next application that allow that google api, tell us what is it.

  • First we need to import the libraries that we are going to use.

import os
import datetime
import shutil
import time
  • Explaining the code.

    • First we kill every instants of eog, this allow us to don't have any demon running.

    • Then we extract the date, so we could make a unique id for each photo.

    • We use os.system("") to give it instruction as we do on terminal.

    • We take the photo using the command fswebcam, and we define some parameters.

    • We move the photo to a specific directory.

    • We show the photo taken for 3 second and we kill it.

def main():
  os.system("killall -9 eog")
  now = datetime.datetime.now()
  name = str(now.year)+"-"+str(now.month)+"-"+str(now.day)+"-"+str(now.hour)+"-"+str(now.minute)+"-"+str(now.second)
  name = str(name)+".jpg"
  os.system("fswebcam -r 800x480 --jpeg 80 --no-banner --save " + name)
  os.system("mv "+name+" /home/lupe/Desktop/photos/"+name)
  os.system("eog -f /home/lupe/Desktop/photos/"+name+" &")
  time.sleep(3)
  os.system("killall -9 eog")
  return 0  

if __name__ == '__main__':
 main()

Last updated