Last active
January 23, 2017 23:46
-
-
Save bhive01/1da70d1b47675a060769edbd1fcb69eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #base packages | |
| import os, sys | |
| import errno | |
| import datetime | |
| import subprocess | |
| from time import gmtime, strftime, sleep | |
| #rPi packages | |
| from picamera import PiCamera | |
| import RPi.GPIO as GPIO | |
| #setup GPIO pins | |
| GPIO.setmode(GPIO.BCM) | |
| GPIO.setup(4,GPIO.IN) | |
| GPIO.setup(12,GPIO.OUT) | |
| #setup Servo | |
| servo=GPIO.PWM(12,50) | |
| servo.start(8.2) #set for RGB image first | |
| #Setup Camera | |
| camera = PiCamera() | |
| camera.rotation = 90 | |
| # Path to be created | |
| # scripts current directory | |
| basepath = sys.path[0] | |
| # make images folder | |
| fullpath = os.path.join(basepath, "images") | |
| # mkdir_p function for creating path in current directory | |
| def mkdir_p(path): | |
| try: | |
| os.makedirs(path) | |
| print("Path is created.") | |
| except OSError as exc: # Python >2.5 | |
| if exc.errno == errno.EEXIST and os.path.isdir(path): | |
| pass | |
| print("Path exists, skipping.") | |
| else: | |
| raise | |
| print("Can't create path, check name.") | |
| mkdir_p(fullpath) | |
| try: | |
| while True: | |
| if GPIO.input(4)==1: | |
| # Take IR photo at 2.5 servo position | |
| # build up filenames | |
| gottime = datetime.datetime.now().strftime("%Y-%m-%d_%H%M%S.%f") | |
| RGBcapname = gottime + '_RGB.jpg' | |
| IRcapname = gottime + '_IR.jpg' | |
| RGBimage = os.path.join(fullpath, RGBcapname) | |
| IRimage = os.path.join(fullpath, IRcapname) | |
| #take image | |
| camera.start_preview() | |
| sleep(0.5) | |
| camera.capture(RGBimage) | |
| camera.stop_preview() | |
| #move servo for IR image | |
| servo.ChangeDutyCycle(2.5) | |
| # Send file via ssh, run script and return IRimage to same directory as RGB one | |
| # http://stackoverflow.com/questions/13332268/python-subprocess-command-with-pipe | |
| catcall = subprocess.Popen(('cat', 'camerawargs.py'), stdout = subprocess.PIPE) | |
| runcall = subprocess.call(['ssh', 'pi@piir.local', 'python3', '-', '-l', IRimage], stdin=catcall.stdout) | |
| # subprocess.call(['ssh', 'pi@piir.local', 'python3', '-u', '-', '--opt' '-l', IRimage, '<', 'camerawargs.py']) | |
| #move servo back for RGB image | |
| servo.ChangeDutyCycle(8.2) | |
| except KeyboardInterrupt: | |
| servo.stop() | |
| GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment