Introduction: Macro Photography Robot for About $15
This Instructable will show you how to build a robot that will help you create fantastic macro shots with your DSLR camera. It will not only create beautiful static images like those shown above, but it can also spin the subject to get a full 360 image and will let you create 3d images and movies of your tiny objects. These photos remind me of scanning electron microscope photos because everything is in focus!
If you like this Instructable, please vote for it in the 'Photography tips and tricks contest' by clicking the 'Vote' icon above. Thanks!
"Why do I need a robot?" you might ask. Well the answer is simple: depth of field. As soon as you start taking closeups, you notice that you just can't get everything in focus at once. With the technique I show in this instructable, it will not only show you how to get everything in focus, but also how to take awesome 360 degree macro photos of your objects! It's a very neat, if a bit involved, project.
Once you collect the necessary materials, you can be up and running in a day.
Step 1: The Concept: Use Many Photos at Different Focus Depths, Then Composite Into One Image Where Everything Is in Focus
If it's unclear to anyone why we need a robot at all, take a look at the photo above. On the right is the original, on the left is the results after using the robot and stitching the photos together. The camera settings are identical. Why is the one on the right have everything in focus? Because it's actually stitched together out of about 25 separate images at different focus distances.
Also, watch the animated gif to see how the depth of field affects the image.
Step 2: Parts and Tools Required, What You're Going to Make
If you're willing to wait, all the materials can be purchaced from China for super cheap! About $15.00 total outlay for a fully operational macro-shooting robot! If you want stuff faster, you can likely find the same stuff available in the USA for maybe double the price.
- Any Arduino with USB connection ($1.99 on ebay, if link broken search for Arduino Nano)
- 2 standard pencils (free) yes, that's right -- who needs linear rails & bearings when you have pencils!)
- Cheapo servo ($1.69 on ebay, if link broken search for 9g micro servo)
- Cheapo stepper motor with driver ( $1.95 on ebay, if link broken, search for 5V stepper motor)
- Extension Tube and/or macro lens to fit your camera. The beauty of an extension tube is that even a super cheap one will do. Search ebay for 'Nikon Extension Tube' or 'Canon Extension tube'. They can be had from china for $7.99 for a set of 3 lengths.
For this Instructable, you'll need access to the following tools
- 3D-printer, or access to a buddy with one.
- Soldering Iron & solder / or breadboard & jumper wires
- DSLR camera, compatible with gphoto. Check for compatible cameras here.
- Any Windows/Mac/Linux computer
- Tripod highly recommended
Step 3: 3d-print the Robot Parts & Assemble Stepper & Servo.
There are only 3 printed parts required, the base, carriage and turntable.
If you'd like to modify these for your own use, feel free. The originals are in Autodesk Inventor, and they are available on Github.
If you'd like to just print-and-go, just download the 3 STL files from this page, and print away.
Step 4: Wire Up the Servo, Stepper and Arduino
You can use any old Arduino that has a USB interface for this step. The schematic here shows and Arduino Micro. There are only 7 wires to connect total, so it should be pretty straight forward
- Connect the Servo: Black to GND, Red to +5V, an signal to pin 8 of the arduino.
- Connect the Stepper motor driver: GND to GND, 5V to 5V, and pins 2, 3, 4 ,5 of the arduino to IN1+, IN1-, IN2+, IN2- respectively.
- I spliced the wires together to make the wiring tidy.
Step 5: Install Arduino Software & Test Out Robot
If you don't already have the Arduino software installed, go and install it. I'll wait.
Okay, that wasn't so bad. Now, we need to upload a test sketch for the servo, and another test sketch for the stepper, and a third one that's the 'production' version.
Test out the stepper
Upload the stepper-test.ino file and give it a go. Your stepper should step rowards, then backwards, then forward, then backwards.
Test out the servo
Upload the servo-test.ino file and give it a go. Your servo should smoothly move from 30 degrees to 130 degrees.
Now you're ready for the big time!
Upload the deep_focus.ino file, which is the arduino sketch that communicates over the USB cable to your computer.
Step 6: Connect Your Macro Extension Tube to Your Camera, Set Up Camera
Connect Extension Tube
This is probably the easiest part of the whole procedure. You actually have several choices on how to turn your camera into a macro camera. You can buy proper macro gear (expensive), or use extension tubes, macro filters, and/or lens reversing rings. The latter 3 are quite cheap. Check google for various methods. Here's one.
The photos on this step show how I do it.
I won't go over too much about camera settings, but here are the basics for my setup:
- set camera to RAW mode
- ISO 100
- Manual exposure
- Aperture about f/11
- Shutter speed: whatever's necessary. Depending on lighting, this can be quite long.
- Set camera to 'Exposure delay mode'
Step 7: Install Python & Control Robot From Python
If you haven't already installed Python, and you don't have a python distro already, you need to install Python. I like Anaconda Python. Follow their instructions for installing. Go ahead. I'll keep waiting.
Make sure you can run it from your command line.
For Mac Users, this means opening the 'Terminal' program, and running python from there.
For Linux Users, same thing, you just run 'python' from a command prompt.
For Windows Users, you run from the 'cmd' window.
Now, run the rotobot_test.py file like this:
This should rotate the turntable, then move the servo. If all's well, you can move to the next step, as shown here.
Step 8: Connect Camera to Computer & Test Out Gphoto
Go get gphoto and install it. I'll wait again. I installed in c:\progs\gphoto2
Connect your camera to your computer over USB
Using the cable that came with your camera, connect your computer to your camera.
Try to take a photo with the following command:
set CAMLIBS=c:\progs\gphoto2\camlibs set IOLIBS=C:\progs\gphoto2\iolibs set CYGWIN=nodosfilewarning c:\progs\gphoto2\gphoto2.bat --capture-image-and-download --force-overwrite
This should create a file called capt0000.nef if all is working well. If it doesn't work, search google for how to set it up right. The commands above worked for me.
Step 9: Test Controlling Gphoto From Python
Once downloaded and extracted, run
This should take a photograph from your camera. If all's well, you're pretty much ready to start taking super macro photos!
Step 10: Do Your First Scan!
Now you're ready for your first scan.
Let's take a simple sequence of 5 photos with the following command:
python deep_focus_rotobot.py --arduino-com-port=COM7 --servo-start 30 --servo-end 130 --servo-steps 5 -d 0 1 test
This creates a set of 5 files in test/000/nef called
And the results look like these photos.
Now, do a full scan
After succes with only 5 photos, you'll want to do a much finer scan of your image. Let's do 25 photos instead of only 5.
python deep_focus_rotobot.py --arduino-com-port=COM7 --servo-start 30 --servo-end 130 --servo-steps 25 -d 0 1 test
Which will give you much better results later.
Step 11: Align Your Photos
Once you have your set of photos, you need to align them. change directory into the test/000/nef directory and align the photos. First you have to convert the photos into a format that align_image_stack can accomodate. So, convert from .nef to .tif
cd test/000 <br>python ../../postprocess.py
That command converts all the files in the nef directory into files in the tif directory.
Now, align the images
cd tif<br>python ../../../photo_stitcher.py --align *.nef -o aligned<br>
This converts the originals that are at different zooms and alignments into a nice well aligned stack of photos.
You can also use photoshop for this, using the image stack commands but I'm not going to cover that here.
Take a look at the attached animated gifs, and you can see how well the align_image_stack program works (that's called from my script 'photo_stitcher.py'.
Step 12: Stitch Your Photos Into One Beautiful, in Focus Image
Now, all we need to do is to run one more program to create an awesome reault.
python ../../../photo_stitcher.py --stack aligned*.tif -o 000_final.tif
this will stitch the 25 source images into what you see here!
Step 13: Create a 3d, Fully In-focus Scan!
Now that you've reached this point, you can use the rotation to create stereograms and other awesomeness.
Simply tell the robot to rotate the bee, like with the following command:
python deep_focus_rotobot.py --arduino-com-port=COM7 --servo-start 30 --servo-end 130 --servo-steps 25 -d 0 36 test
The only difference here is that we told it to run 25 photos, in each of 36 directions! I.e. you'll have a beautiful image ever 10 degrees. I did this, then merged the images into a rotating stereogram!
Here's a 360 degree view of a bee
And here it is in 3D! If you don't know how to view a stereogram, search for it on google, it's very neat. It may help to view it on your phone to get the full 3d effect. This stereogram has 5 degrees between the images, and the next is 10 degrees between the images.
Participated in the
Photography Tips and Tricks Contest