Posts Tagged ‘Photography’

Panoramaker

As promised before, here is the Python script that runs my panoramic camera hardware. It is a very quick prototype and is by no means intended for widespread use since it requires manual calibration. Nevertheless, it might be very useful to those seeking to learn how to position the servos or control a digital camera through Python.

This script requires my Pololu library and includes some codes from here in order to control the camera. Besides the basic requirements of lib_pololu,  the script also requires gPhoto. If you are running Linux, you most likely  already have it but in case you do not, you can install it through your favourite package manager or by using the console (e.g. for Ubuntu/Debian):

sudo apt-get install gphoto

If you are using some other OS, you can download gPhoto from here.

The Code

Download
# 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()
 

Again, many thanks to RobotShop who provided the hardware that made this project possible.

Panoramic Camera – Prototype

Update:

Read the follow up posts: Panoramaker, where I expose the software, and Automatic Panoramas in Montreal, where the final result can be seen.

I have finally completed my second project sponsored by RobotShop. I apologize for the immense delay, I really missed my promise of rolling out a new project every two weeks. Let’s just say that I had a lot going on lately and I could barely keep up with my obligations, let alone blogging or building new projects.

Place Ville Marie Panorama

Place Ville-Marie Panorama

This time, I built a panoramic camera. My main objective was to have a platform that can be used with pretty much any camera and that can produce panoramas with a minimum of work. If there is enough interest from the public and if this prototype is well received by the DIY community, I’m planning to produce (and hopefully sell) kits that would include all the parts to build this device.

Materials

Putting It Together

Panoramic Camera Mount

Panoramic Camera Mount

The first step was to put together the ServoCity Pan and Tilt system. This took away much of the building work since it is really simple to put together in no time at all. Nevertheless, I applied some modifications to it: I discarded the bottom plate that should be attached to the panning servo (since I am using a larger winch servo that would not fit otherwise), and I drilled a hole on the top plate in order to be able to fasten the camera to the rig. Note that I also included a little piece of neoprene that was lying around in order to prevent the bottom of my camera from getting scratched.

The mounting hole for the camera must be placed so that the lens’ pupil is at the centre of rotation. This way, the horizontal rotation axis will be close to the no-parallax-error point  (or whatever it is called) of the camera and will minimize the parallax errors.

Then, I used an old heat sink as the main structure since it is sturdy and basically free. I used the trusty Dremel to adapt it and cut the proper holes and slots in order to mount all the remaining pieces. The pieces to be mounted on the aluminum plate are the battery holders, the Pololu servo controller, and the winch servo motor. (or whatever it is called

I encapsulated the Pololu servo controller in a small plastic container I got from for free while on a trip with my girlfriend to the beauty/ soap/cream shop. I also used two 2-AA battery holders in order to provide power for the servo motors. I used 29000 mAh NiMH rechargeable batteries that gave me several hours of autonomy. In order to connect the battery holders to the controller, I soldered a two-position female header and insulated the leads with heat-shrink tubing.

I used almost exclusively cable ties to tie everything on the aluminum plate except for the winch servo motor that I screwed in and the long nut that was also screwed in place (after being drilled sideways).  I also had to drill the bottom aluminum face in order to allow for the tripod screw to be inserted into the nut.

Operating it

Panoramic camera in action

Panoramic camera in action

This first prototype requires a laptop to be operated, which can be a little annoying.  I plan to use my EeePC in the immediate future and an embedded computer for an eventual commercial kit. It basically works as follows:

  1. The camera is set on the panoramic mount, which is fastened to the tripod.
  2. The servo controller and the camera are connected to the computer trough their respective USB cables.
  3. The controlling program is run.
  4. The user waits in awe while the camera takes pictures by itself.

In order to control the hardware, I use a python script that uses my Pololu library and gPhoto in order to operate the servos and the camera respectively. I chose gPhoto since it supports a very wide range of cameras and it is very easy to use.

For now, taking a full 360 panorama takes about 15 minutes. This is a very long time and is mostly due to the fact that my script was hastily put together without care about the performance and in very little time. I will, very soon, post a cleaner version of the code, as well as all the panoramas I took properly processes and in full format, similarly to what I did with my San Francisco panoramas.

Acknowledgements

RobotShop.com

RobotShop.com

I would like to thank the great people at RobotShop for providing the Pololu Micro Serial Servo Controller, the  ServoCity SPT200 Direct Drive Pan & Tilt System, and the Hitec HS-785HB Winch Servo Motor. This is the second (and hopefully not the last) project they sponsor here at Carlitos’ Contraptions. Without their help, I would have never been able to afford any of the materials (except for those that come straight from the garbage as usual).

They have also being very patient and understanding about my unexpected delay in rolling out this project.

http://carlitoscontraptions.com/2009/05/making-panoramas/

Making Panoramas

In my trip to San Francisco, I had the chance to see many beautiful things. And I wanted to be able to remember them and show them to my friends and family.

San Francisco Seen Form Twin Peaks Park

San Francisco Seen Form Twin Peaks Park

Besides taking simple photos, sometimes you need a wider view- angle to really capture the scenery. The obvious solution to this is making a panorama. This means you take many pictures of different sections of your subject and then align them and stitch them together so to form a bigger picture.

Many people believe this is a very difficult procedure and that the results are never as good as expected, and they are partially correct. In order to get a nice looking panoramic picture hat will align and stitch together correctly you need to follow some rules:

  • Make sure that contiguous pictures have a good 30% overlap between them.
  • Make sure the overlapping areas contains some hard object, like a building. If they overlap only over the sky or some water, then the stitching together will be more difficult.
  • Make sure you follow a simple pattern when shooting the photos. Follow a horizontal line, for instance, and shoot the pictures in order. Also, if your making a taller panorama, I suggest you shoot many horizontal lines that will stack up together. This will make things easier when recognizing which photos to stitch together.
  • Make sure all the pictures have a similar exposure. This should be no problem if you are shooting your pictures all at once.
  • Make sure your subject is always on the same focal plane. You can have many focal panes but it will make the stitching more difficult.

Once you have shot all the pictures you can start the stitching. In order to so so, you can use an excellent software package called Hugin. Of course since I’m using it, Hugin is open source and (thus) cross-platform. Is is a very intuitive program to use and since there are many good tutorials about it, I won’t be outlining the instructions on how to use it.

Once you stitched your images together (which can be done in the three steps the wizards takes you trough) you will end up with a big TIFF or JPG file.  Now you are basically done. Now you just need to crop it and made any desired adjustments with a picture editing program lie Gimp.

The only problem is that if you want to share this picture it can be hard since it may be too big for sending by email and will take a long time to (upload and) download if you put it on a website.

Now you can use the Google Maps Image Cutter. This little Java program developed by UCL enables you to use the Google Maps engine as a picture viewing system. It creates many copies of your image at various resolutions and chops those images into small square pieces. Then when you view the image trough the google maps engine, you are only loading the small squares at which you are currently looking at the resolution corresponding to your zoom level.

Here you can enjoy a few examples I made (click on the title to view them in full screen).

Title: Downtown San Francisco
Description: A panorama shot from the Twin Peaks Park.
Title: Downtown and East San Francisco
Description: A larger panorama shot from the Twin Peaks Park.
Title: South San Francisco
Description: Another panorama shot from the Twin Peaks Park.

Keep in mind that Hugin is very powerful and can do much more than simply stitching a few images together. Also, there might be a few issues with the file writing routine when trying to run the Google Maps Image Cutter in Linux.

Return top

Welcome!

Here you will find my DIY projects, Robotic hacks, Nao 1337 videos, and more! Have questions about a project? Leave a comment!
    • I am a Jr. Electrical Engineer Graduated from McGill University. I am very passionate about robotics and open source technology. I love to tinker and make things. My goal is to become a kick-ass engineer and roboticist by contributing to the development of personal robots.