fork download
  1. import threading
  2. import os
  3. import time
  4. import picamera
  5. import datetime
  6.  
  7. numberOfImages = 0
  8. inputing = True
  9.  
  10. days = 0
  11. h = 0
  12. m = 0
  13. s = 0
  14. secounds = 0
  15. delay = 300
  16.  
  17.  
  18.  
  19. while inputing:
  20. os.system('cls' if os.name == 'nt' else 'clear')
  21. try:
  22. numberOfImages = int(raw_input('How many images should be taken? \'0 to ignore\'\n'))
  23. if numberOfImages == 0:
  24. days = int(raw_input('How many days should this take?\n'))
  25. h = int(raw_input('How many hours should this take?\n'))
  26. m = int(raw_input('How many minutes should this take?\n'))
  27. s = int(raw_input('How many secounds should this take?\n'))
  28. pass
  29. delay = int(raw_input('How long delay (in sec) \n'))
  30. print "\n\n In what resolution ? \n\n"
  31. inputing = False
  32. if delay == 0:
  33. delay = 1
  34. pass
  35. except Exception as err:
  36. print 'Error: ' + err
  37.  
  38.  
  39. if numberOfImages == 0:
  40. days = days * 24 * 60 * 60
  41. h = h * 60 * 60
  42. m = m * 60
  43. secounds = days + h + m + s
  44.  
  45. numberOfImages = secounds / delay
  46. pass
  47.  
  48. print "\n\nLoading settings... \n\n"
  49.  
  50. class timelaps(threading.Thread):
  51. """docstring for timelaps"""
  52. def __init__(self, delay, numberOfImages):
  53. super(timelaps, self).__init__()
  54. self.delay = delay
  55. if delay < 20:
  56. self.delay = 20
  57. pass
  58. self.numberOfImages = numberOfImages
  59.  
  60.  
  61. def run(self):
  62. currentImage = 0
  63. camera = picamera.PiCamera() #Im getting the error here!
  64. camera.resolution(2592, 1944)
  65. extraTime = 0
  66. numberoferrors = 0
  67. errors = 0
  68. while currentImage < self.numberOfImages:
  69. timestamp = int(time.time())
  70. timeleft = (numberOfImages - currentImage) * self.delay
  71.  
  72. d = datetime.timedelta(seconds = timeleft)
  73.  
  74. #print("DAYS:HOURS:MIN:SEC")
  75. #print("%d:%d:%d:%d" % (d.days-1, d.hour, d.minute, d.second))
  76.  
  77. os.system('cls' if os.name == 'nt' else 'clear')
  78. print " ==================================="
  79. print " | Number of taken images: " + str(currentImage) + " |"
  80. print " |---------------------------------|"
  81. print " | Time left : " + str(d)
  82. print " | Seconds left : " + str(timeleft)
  83. if numberoferrors > 0:
  84. print " | Number of errors: " + str(numberoferrors)
  85. print " ==================================="
  86.  
  87.  
  88. try:
  89. print " | Warming upp camera |\n"
  90.  
  91. # Warming upp camera
  92. camera.start_preview()
  93. time.sleep(2)
  94.  
  95. # Creating the image after 2 sec of warmup
  96. camera.capture('images/' + str(timestamp) + '.jpg')
  97. #Shuting down camera to wait on the next image
  98. camera.stop_preview()
  99. # Add 1 to current image, to display and
  100. # keep track of number of images created
  101. print " | Saved |\n"
  102. currentImage += 1
  103. extraTime = 0
  104. except Exception as e:
  105. print e
  106. print "Error while trying to create: " + str(timestamp) + ".jpg"
  107. errors += 1
  108. numberoferrors += 1
  109. # If there is more than 5 errors the dilay will be 2x more
  110. if errors > 5:
  111. extraTime = self.delay
  112. errors = 0
  113. pass
  114. raise
  115. else:
  116.  
  117. pass
  118. finally:
  119.  
  120. pass
  121.  
  122.  
  123. try:
  124. print "Running delay on " + str(delay) + " S"
  125. print "Please hold!"
  126. timelaps2 = int(time.time())
  127. time.sleep( int(self.delay) - ( int(timelaps2) - int(timestamp) ) )
  128. except (KeyboardInterrupt, SystemExit):
  129. print "============================"
  130. print "| Shuting down script now! |"
  131. print "============================"
  132. currentImage = self.numberOfImages
  133. raise
  134.  
  135.  
  136.  
  137.  
  138. #########################################################################################################
  139. #########################################################################################################
  140. #########################################################################################################
  141.  
  142. thread_capture = timelaps(delay, numberOfImages)
  143.  
  144.  
  145. thread_capture.start()
  146.  
  147.  
  148. thread_capture.join()
  149.  
  150. print "\n\n\nAll done !\n\n\n"
  151. #########################################################################################################
  152. #########################################################################################################
  153. #########################################################################################################
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
Runtime error #stdin #stdout #stderr 0.04s 42160KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Warning: cannot find your CPU L2 cache size in /proc/cpuinfo
Traceback (most recent call last):
  File "app_main.py", line 75, in run_toplevel
  File "prog.py", line 4, in <module>
    import picamera
ImportError: No module named picamera