Deprecated: Function set_magic_quotes_runtime() is deprecated in /home/dfmoore/notes.binarytree.org/textpattern/lib/txplib_db.php on line 14
Notes: Structured Light scanning from scratch

Notes

 
 

Structured Light scanning from scratch

Oct 24, 09:21 AM

Structured light scanning on the Mac
I’m putting together notes as I walk through the process of writing a structured light scanner from scratch for the mac. I’m going to put all of the code up here, but no promises until I get it working!

What camera I’m using:
I’m using a Canon EOS Rebel T1i because it’s wicked sweet. And supported ( ;
libgphoto2 has an impressive list of supported cameras, so I figure if I use that, other people can benefit even with different cameras.
Supported Cameras

What projector I’m using:
Just an old off-the-shelf sony projector. Nothing special. nothing expensive.



Step 1 Get all of the software parts you need to capture images from your camera.
I’m using MacPorts because it makes this kind of thing waaay less painful.
Get it here. After installing, type
In the terminal:
sudo port libgphoto2
sudo port gphoto2

Make sure your environment variables are pointing to the macport sandbox folders.
In the terminal:
cd /etc
sudo pico profile

and edit the PATH variable to include /opt/local, like this:
export PATH=/opt/local/bin:/opt/local/include:/opt/local/sbin:$PATH

That last :$PATH part is important, so you can set other environment variables elsewhere, and this just appends ours.

close your terminal window and open a new one after setting environment variables, or they won’t be in effect.



Step 2 Test that your camera can connect with libgphoto2 by hooking up your camera, turning it on (wait a second) and typing
gphoto2 --auto-detect
This is what I see.

Model                           Port                                            
----------------------------------------
Canon EOS 500D                 usb:            
Canon EOS 500D                 usb:038,003     

Excellent details on how to use the Command Line Interface (CLI) can be found here.

Step 3 PTPCamera will make you hate life. Kill it with fire.
So, if you actually try to grab an image, you’ll most likely get an error saying that something else is using the camera already. In this case, it’s PTPCamera, a daemon that launches on a macintosh every time you plug in a camera. This is good if you’re using iPhoto, Aperture, or something like that. The best way to tell if PTPCamera is running is to type:
ps -e | grep PTP
If you see TWO lines printed out after this, with some involved camera info, then this is the process you want to kill. I should mention that I ran into a great blog by DC Clark that helped me pinpoint the problem. His solution involves kill -9’ing the process (ending it in the terminal) every time you plug in the camera. Here’s what I’m doing instead:

  • Make a blank, plain text document and put the following in:
    #!/bin/bash
    echo "Remember, you disabled PTPCamera so you could play with gphoto2."
    exit 0

and save it as PTPCamera, with NO FILE EXTENSION. If you have extensions hidden by default on your mac, turn them on and make sure this doesn’t have one.

  • Open up a terminal window, and type:
    sudo chmod +x and then drag the text file into the terminal to add its path. Hit enter. This makes it executable by the system.
  • In the finder, in the “Go” menu, choose “Go to folder” and type
    /System/Library/Image\ Capture/Devices/PTPCamera.app/Contents/MacOS
    where you should see a lonely executable sitting there called PTPCamera. We want to keep this file around, so we’ll need to give it a new name, like “PTPCamera Backup”. Renaming it is a little weird, since it’s in a special permissions place. You might want to drag a copy to the desktop, rename it there, drag it back in (authenticate), and then delete the originally named file. Then, move your text file into this folder too.

What you should have: The old PTPCamera daemon, renamed to something else, and your executable script named PTPCamera.

What does this all do? When you plug in a camera, it’ll run the script instead, print a message to the system console reminding you that you were mucking with this, and then exit with a return value of zero. This will make the system think the daemon is happily running, while in reality, it never gets launched.

How can I undo this? Get rid of your script, and rename the PTPCamera Backup back to “PTPCamera”. Good as new.

Step 4 Setting up an Xcode project
I’ll eventually be setting up an Objective C project, but for now, I’m going to work with a simple standard C tool.

  • Start by creating a new project with the “Standard Tool” template.
  • Right click on the project icon and choose “Add>Existing Frameworks”.
  • Navigate to /opt/local/bin/ and select gphoto2, gphoto2-config and gphoto2-port-config. Add those to your project.
  • Also navigate to /opt/local/lib/ and select libgphoto2_port.0.8.0.dylib, libgphoto2_port.0.dylib, libgphoto2_port.dylib, libgphoto2_port.la, and.. well, any other libgphoto dylib’s and la’s.
  • Next, right click on the project and choose Get Info. Under the build tab, find “Search Paths”. For “Header Search Path”, write /opt/local/include/. Under “Library Search Path”, write /opt/local/lib/.

Comments