Created
September 18, 2012 22:40
-
-
Save Sotilrac/3746452 to your computer and use it in GitHub Desktop.
Panoramaker
This file contains 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
# -*- coding: utf-8 -*- | |
################################################################################ | |
##Author: Carlos Asmat | |
##Creation Date: 12/09/09 | |
##Title: Panoramaker | |
## | |
##Copyright: Carlos Asmat, 2009 | |
##License: | |
## This program is free software: you can redistribute it and/or modify | |
## it under the terms of the GNU General Public License as published by | |
## the Free Software Foundation, either version 3 of the License, or | |
## (at your option) any later version. | |
## | |
## This program is distributed in the hope that it will be useful, | |
## but WITHOUT ANY WARRANTY; without even the implied warranty of | |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
## GNU General Public License for more details. | |
## | |
## You should have received a copy of the GNU General Public License | |
## along with this program. If not, see <http://www.gnu.org/licenses/>. | |
## | |
##Description: | |
## This is a simple script that uses the lib_Pololu library among others | |
## in order to capture a 360 deg panorama. | |
## | |
################################################################################ | |
# Adding the path to the lib_pololu.py file to your modules path. | |
# Assuming that the file is at /your/path/to/the/library/lib_pololu.py | |
import sys | |
sys.path.append('/your/path/to/the/library') | |
# Import the lib_pololu module | |
import lib_pololu | |
# Import the serial communication and time modules | |
import serial | |
import time | |
# Open serial port | |
port = serial.Serial('/dev/ttyUSB1') | |
port.baudrate=2400 #set an appropriate baudrate | |
# Camera Code (from vmlaker.org) | |
import os, re | |
from subprocess import call, Popen, PIPE | |
def run(command): | |
print 'Running:', command | |
p = Popen(command, shell=True, stdout=PIPE) | |
lines = p.stdout.readlines() | |
for line in lines: | |
print 'Stdout :', line, | |
return lines | |
def capture(): | |
c = 'gphoto2 --capture-image' | |
sout = run(c) | |
firstLine = sout[0] | |
expr = 'New file is in location (.*?) on the camera' | |
comp = re.compile(expr, re.DOTALL) | |
path = re.findall(comp, firstLine)[0] | |
dir, fname = os.path.split(path) | |
c = 'gphoto2 --get-file %s --folder %s'%(fname, dir) | |
run(c) | |
c = 'gphoto2 --delete-file %s --folder %s'%(fname, dir) | |
run(c) | |
c = 'gphoto2 --storage-info' | |
run(c) | |
# Calibration Parameters | |
# These parameters set the limits and reference positions of the rig. | |
# They have been obtained trough trial and error. | |
horizontal = 93.5 | |
front = 95.5 | |
back_l = 84.5 | |
back_r = 107 | |
top = 70 | |
bottom = 110 | |
# Create two motors | |
# There are associated to the panning and tilting motion of the rig. | |
tilt = lib_pololu.Servo(port, 0, 1150, 4650) | |
pan = lib_pololu.Servo(port, 1, 1200, 4987) | |
# Define a capture routine | |
# This is a simple loop that takes pictures in order to produce a | |
# 360 deg panorama. | |
def capture_pano(): | |
# Capture parameters | |
steps_h = 16 | |
steps_v = 4 | |
step_h = (back_r - back_l)/steps_h | |
step_v = (bottom - top)/steps_v | |
pos_v = bottom | |
while (pos_v >=top): | |
tilt.set_pos(pos_v) | |
pos_v = pos_v - step_v | |
pos_h = back_l | |
while(pos_h <= back_r): | |
pan.set_pos(pos_h) | |
pos_h = pos_h + step_h | |
time.sleep(2) | |
capture() | |
# Initialize the motors | |
tilt.set_pos(horizontal) | |
pan.set_pos(front) | |
time.sleep(2) | |
# Capture the panorama | |
capture_pano() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment