Advertisement
Aintence__

Untitled

Aug 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.54 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. #  raspiLapseCam.py
  4. #
  5. #  Created by James Moore on 28/07/2013.
  6. #  Copyright (c) 2013 Fotosyn. All rights reserved.
  7. #
  8. #  Raspberry Pi is a trademark of the Raspberry Pi Foundation.
  9.  
  10. #  Redistribution and use in source and binary forms, with or without
  11. #  modification, are permitted provided that the following conditions are met:
  12.  
  13. #  1. Redistributions of source code must retain the above copyright notice, this
  14. #  list of conditions and the following disclaimer.
  15. #  2. Redistributions in binary form must reproduce the above copyright notice,
  16. #  this list of conditions and the following disclaimer in the documentation
  17. #  and/or other materials provided with the distribution.>
  18.  
  19. #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. #  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. #  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. #  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  23. #  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. #  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. #  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  26. #  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. #  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. #  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  
  30. #  The views and conclusions contained in the software and documentation are those
  31. #  of the authors and should not be interpreted as representing official policies,
  32. #  either expressed or implied, of the FreeBSD Project.
  33.  
  34. # This script sets up and runs a Python Script which, at intervals invokes a capture
  35. # command to the Raspberry Pi camera, and stores those files locally in a dynamically
  36. # named folder.
  37.  
  38. # To invoke, copy this script to an easy to find file location on your Raspberry Pi
  39. # (eg. /home/pi/), log into your Raspberry Pi via terminal and type:
  40. #
  41. # sudo python /your/file/location/raspiLapseCam.py (add &) if you wish to run as a
  42. # background task. A process ID will be shown which can be ended with
  43.  
  44. # sudo kill XXXX (XXXX = process number)
  45.  
  46. # Based on your settings the application will no begin capturing images
  47. # saving them to your chose file location (same as current location of this file as default.
  48.  
  49. # Import some frameworks
  50. import os
  51. import time
  52. import RPi.GPIO as GPIO
  53. from datetime import datetime
  54.  
  55. # Grab the current datetime which will be used to generate dynamic folder names
  56. d = datetime.now()
  57. initYear = "%04d" % (d.year)
  58. initMonth = "%02d" % (d.month)
  59. initDate = "%02d" % (d.day)
  60. initHour = "%02d" % (d.hour)
  61. initMins = "%02d" % (d.minute)
  62.  
  63. # Define the location where you wish to save files. Set to HOME as default.
  64. # If you run a local web server on Apache you could set this to /var/www/ to make them
  65. # accessible via web browser.
  66. folderToSave = "timelapse_" + str(initYear) + str(initMonth) + str(initDate) + str(initHour) + str(initMins)
  67. os.mkdir(folderToSave)
  68.  
  69. # Set the initial serial for saved images to 1
  70. fileSerial = 1
  71.  
  72. # Run a WHILE Loop of infinitely
  73. while True:
  74.    
  75.     d = datetime.now()
  76.     if d.hour > 2:
  77.        
  78.         # Set FileSerialNumber to 000X using four digits
  79.         fileSerialNumber = "%04d" % (fileSerial)
  80.        
  81.         # Capture the CURRENT time (not start time as set above) to insert into each capture image filename
  82.         hour = "%02d" % (d.hour)
  83.         mins = "%02d" % (d.minute)
  84.        
  85.         # Define the size of the image you wish to capture.
  86.         imgWidth = 800 # Max = 2592
  87.         imgHeight = 600 # Max = 1944
  88.         print " ====================================== Saving file at " + hour + ":" + mins
  89.        
  90.         # Capture the image using raspistill. Set to capture with added sharpening, auto white balance and average metering mode
  91.         # Change these settings where you see fit and to suit the conditions you are using the camera in
  92.         os.system("raspistill -w " + str(imgWidth) + " -h " + str(imgHeight) + " -o " + str(folderToSave) + "/" + str(fileSerialNumber) + "_" + str(hour) + str(mins) +  ".jpg  -sh 40 -awb auto -mm average -v")
  93.  
  94.         # Increment the fileSerial
  95.         fileSerial += 1
  96.        
  97.         # Wait 60 seconds (1 minute) before next capture
  98.         time.sleep(60)
  99.        
  100.     else:
  101.        
  102.         # Just trapping out the WHILE Statement
  103.         print " ====================================== Doing nothing at this time"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement