How to get PTAM and PTAMM running on OSX 10.6 (and probably 10.7)

The build instructions in PTAMM for OSX are now out of date if you are using the latest OSX 10.6 and above. I shall update the manual shortly, but until then follow this guide to get PTAM and PTAMM up and running on OSX.

Check out the latest libCVD and GVars

cvs -z3 -d:pserver:anoncvs@cvs.savannah.nongnu.org:/cvsroot/libcvd co libcvd
cvs -z3 -d:pserver:anoncvs@cvs.savannah.nongnu.org:/cvsroot/libcvd co gvars3

I checked mine out on Fri 30th Sept 2011. As this is the CVS repo, things may change rapidly.

Edit the two lines in configure-10.5-32bit in PTAMM to point to the SDK that actually exists on your machine. It will be one of these:

  • MacOSX10.5.sdk
  • MacOSX10.6.sdk
  • MacOSX10.7.sdk

Then add -D_OSX to the end of the first three export lines, but inside the quotes. This define is for a modification we are going to have to make to libCVD in a moment. If the repo has been updated and contains this fix you may not need to add this define.

Your configure-10.5-32bit should now look like this:

#!/bin/bash
#This script forces Snow Leopard (10.6) to build using Leopard (10.5) and to build a 32 bit build.
# Use it when building livCVD, GVars, and lib3ds
#
# Originally wirrten by Damian Stewart
# http://lists.nongnu.org/archive/html/libcvd-members/2010-05/msg00000.html
# Modified by Robert Castle

SDK="-isysroot /Developer/SDKs/MacOSX10.6.sdk"
SDKLIB="-Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk"
export MACOSX_DEPLOYMENT_TARGET="10.5"

ARCH="-arch i386"

export CFLAGS="$ARCH $SDK -mmacosx-version-min=10.5 -m32 -D_OSX"
export CXXFLAGS="$ARCH $SDK -mmacosx-version-min=10.5 -m32 -D_OSX"
export CPPFLAGS="$ARCH $SDK -mmacosx-version-min=10.5 -m32 -D_OSX"
export LDFLAGS="$ARCH $SDKLIB -mmacosx-version-min=10.5 -m32"

CC="/usr/bin/gcc-4.2"
CXX="/usr/bin/g++-4.2"
OBJC="/usr/bin/gcc-4.2"

./configure $1 $2 $3 $4 $5 $6 $7 $8 $9

Copy configure-10.5-32bit from PTAMM into the libCVD and GVar directories.

Now we need to make some changes to libCVD (unless they have been fixed already).

pnm_src/pnm_grok.cxx line 634
change n to n_shorts

cvd_src/Linux/dvbuffer3_dc1394v2.cc lines 131 and 158
add ULL to the long numbers
0x814436200006075ULL

cvd/gl_helpers.h
This is where we need the _OSX define. We need to point it to the Apple OpenGL framework and not the X11 OpenGL files.

change

#include <GL/gl.h>
#include <GL/glu.h>

to

#ifdef _OSX
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif

progs/calibrate.cxx line 813
Apple’s GL files do not have GL_TEXTURE_RECTANGLE_NV defined so we need to make this a bit more platform agnostic. I have not tested these changes on Linux or Windows, but I think they should be fine.
Replace the block of gl code between the GL_BLENDs with this. All it changes is GL_TEXTURE_RECTANGLE_NV into texTarget and adds the #ifdefs to the top.

	GLenum texTarget;
#ifdef GL_TEXTURE_RECTANGLE_ARB
	texTarget=GL_TEXTURE_RECTANGLE_ARB;
#else
#ifdef GL_TEXTURE_RECTANGLE_NV
	texTarget=GL_TEXTURE_RECTANGLE_NV;
#else
	texTarget=GL_TEXTURE_RECTANGLE_EXT;
#endif
#endif

	glEnable(texTarget);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glTexParameterf( texTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	glTexParameterf( texTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
	glPixelStorei(GL_UNPACK_ALIGNMENT,1);
	glTexImage2D(temp, 0, texTarget);
	glBegin(GL_QUADS);
	glTexCoord2i(0, 0);
	glVertex2i(0,0);
	glTexCoord2i(temp.size().x, 0);
	glVertex2i(disp.size().x,0);
	glTexCoord2i(temp.size().x,temp.size().y);
	glVertex2i(disp.size().x,disp.size().y);
	glTexCoord2i(0, temp.size().y);
	glVertex2i(0, disp.size().y);
	glEnd ();
	glDisable(texTarget);

progs/video_play_source.cc line 73
This is a similar change to the last.

	GLenum texTarget;
#ifdef GL_TEXTURE_RECTANGLE_ARB
	texTarget=GL_TEXTURE_RECTANGLE_ARB;
#else
#ifdef GL_TEXTURE_RECTANGLE_NV
	texTarget=GL_TEXTURE_RECTANGLE_NV;
#else
	texTarget=GL_TEXTURE_RECTANGLE_EXT;
#endif
#endif

	glEnable(texTarget);
	for(;;)
	{
		display.get_events(e);
		if(e.should_quit())
			break;

		VideoFrame<C>* frame = buffer->get_frame();

		glViewport(0, 0, display.size().x, display.size().y);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glRasterPos2f(-1, 1);
		glOrtho(-0.375, display.size().x-0.375, display.size().y-0.375, -0.375, -1 , 1); //offsets to make (0,0) the top left pixel (rather than off the display)

		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		glTexParameterf( texTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
		glTexParameterf( texTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
		glPixelStorei(GL_UNPACK_ALIGNMENT,1);
		glTexImage2D(*frame, 0, texTarget);
		glBegin(GL_QUADS);
		glTexCoord2i(0, 0);
		glVertex2i(0,0);
		glTexCoord2i(frame->size().x, 0);
		glVertex2i(display.size().x,0);
		glTexCoord2i(frame->size().x,frame->size().y);
		glVertex2i(display.size().x,display.size().y);
		glTexCoord2i(0, frame->size().y);
		glVertex2i(0, display.size().y);
		glEnd ();

		if(f)
		{
			cout << "frame size: " << frame->size() << endl;
			f=0;
		}
		buffer->put_frame(frame);
		glFlush();

		display.swap_buffers();
	}
	glDisable(texTarget);

Then build libCVD and GVars3

cd libcvd
./configure-10.5-32bit --prefix=$HOME/local/
make -j3 && make install

My configure options look like this:

Options:
inline_asm dc1394v2 qtbuffer videodisplay tr1_shared_ptr toon lapack pthread png jpeg tiff glob memalign

Missing options for darwin10.8.0:
assembler ffmpeg posix_rt

Dodgy things:
missing_c99_feenableexcept

SIMD support:
mmx mmxext sse sse2 sse3

Missing SIMD support for i386-apple-darwin10.8.0:

Now build GVars3

cd ../gvars3
./configure-10.5-32bit --prefix=$HOME/local/
make -j3 && make install

I did not need to make any other changes to libCVD or GVars.

Now on to PTAM

cd ../PTAM
cp Build/OSX/* .
vim Makefile

Edit the location of your include and lib paths, eg $(HOME)/local/include and $(HOME)/local/lib.

Then add -arch i386 to the end of the CC line, e.g.

CC = g++ -g -O3 -arch i386

Finally add -m32 to the end of the COMPILEFLAGS and LINKFLAGS lines, e.g.

COMPILEFLAGS = -I $(HOME)/local/include -D_OSX -D_REENTRANT -m32
LINKFLAGS = -framework OpenGL -framework VecLib -L$(HOME)/local/lib/ -lGVars3 -lcvd -m32

Now build PTAM

make -j3

Finally on to PTAMM. PTAMM already has the 32-bit changes in the Makefile, so just set your include and lib paths.

cd ../PTAMM
vim Makefile
make -j3

If you want to use the 3D model game, you also need to build lib3DS. Use the configure-10.5-32bit script to build this as well.

I have tested this with a Logitech C910 and both PTAM and PTAMM work well.

Let me know how you all get on with this, and if it works on Lion.

Advertisements

About Robert Castle

Freelance consultant at Egomotion Limited, specialising in augmented reality, computer vision, Unity, mobile and desktop apps.
This entry was posted in OSX, ptam, ptamm. Bookmark the permalink.

33 Responses to How to get PTAM and PTAMM running on OSX 10.6 (and probably 10.7)

  1. watsonwatson123456 says:

    After changing the “configure-10.5-32bit” file, you don’t tell where we should copy it. It sais just “Copy configure-10.5-32bit from PTAMM into these directories.”. Could you edit it and say where to copy it? Thanks.

    • You need to copy the configure script to directories for libCVD, GVars, and lib3ds (if you are using it).

      • watsonwatson123456 says:

        Thanks! Now I’m having problems compiling PTAM. I get this error:

        ld: warning: ignoring file /usr/local/lib//libcvd.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

        I have double checked that my “configure-10.5-32bit” in libcvd has the option ARCH=”-arch i386″ so I don’t know what is the problem.

  2. watsonwatson123456 says:

    Well, I just recompiled (several times) CVD and now it works.

  3. Thank you. It works fine. The most time consuming part was updating my MacPorts install.
    By the way, I had to change the line 173 in libcvd/progs/video_play_source.cc as follows:
    glTexImage2D(*frame, 0, texTarget);

  4. Vinis says:

    Hi Robert, awesome instruction you provide here.
    But i still encounter compile error in terminal as below:

    /usr/local/include/TooN/internal/objects.h: In constructor ‘GLWindow2::GLWindow2(CVD::ImageRef, std::string)’:
    /usr/local/include/TooN/internal/objects.h:35: error: argument dependent lookup finds ‘struct TooN::Internal::Zero’
    GLWindow2.cc:37: error: in call to ‘Zero’
    /usr/local/include/TooN/internal/objects.h:35: error: argument dependent lookup finds ‘struct TooN::Internal::Zero’
    GLWindow2.cc:38: error: in call to ‘Zero’

    Any idea what caused it? I’ve been trying to run this work on macbook pro for further study, hope can get some help here.

    • Vinis says:

      Never mind my previous comment. Finally, managed to build it after fiddling around for hours for both PTAM and PTAMM…
      Turned out i was using the old version of PTAM source code in my previous attempt =.=

      A quick note for lib3ds: it’s best to grab the latest stable one in the download lib3ds-20080909.zip and build that one using the same configure script provided here (i can’t make the latest repo build to work).

      Thanks for sharing this awesome work!!

  5. Thanks for a great write up, though I managed to have this running on snow leopard a while ago, I’ve never got it running on Lion. With these new instructions I’m getting there (also thanks to Joo-Haeng Lee’s comment above), but I am sticking with the following error on gvars3:

    ~/_Working/PTAMM/gvars3$ make
    g++ -I. -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -m32 -D_OSX -I /sw/include -I/opt/local/include -I/usr/X11R6/include -I/Users/ajc/local/include -DGUI_HAVE_READLINE -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -m32 -D_OSX -Wall -Wextra -pthread -I. -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -m32 -D_OSX -I /sw/include -I/opt/local/include -I/usr/X11R6/include -I/Users/ajc/local/include -DGUI_HAVE_READLINE -c -o src/GUI_readline.o src/GUI_readline.cc
    src/GUI_readline.cc: In static member function ‘static void* GVars3::spawn_readline_thread::proc(void*)’:
    src/GUI_readline.cc:69: error: ‘rl_event_hook’ was not declared in this scope
    src/GUI_readline.cc: In destructor ‘GVars3::spawn_readline_thread::~spawn_readline_thread()’:
    src/GUI_readline.cc:96: error: ‘rl_done’ was not declared in this scope
    src/GUI_readline.cc: In constructor ‘GVars3::readline_in_current_thread::readline_in_current_thread(const std::string&)’:
    src/GUI_readline.cc:117: error: ‘rl_event_hook’ was not declared in this scope
    src/GUI_readline.cc:118: error: ‘rl_set_keyboard_input_timeout’ was not declared in this scope
    make: *** [src/GUI_readline.o] Error 1

    Which seems to be a readline problem. I installed readline(6.2) via homebrew, but still doesn’t seem to be working. If I run the configure script with –disable-widgets –without-readline everything makes fine, including PTAMM, but I cannot run the binaries. Instead getting this error:

    ~/_Working/PTAMM/PTAMM$ ./CameraCalibrator
    dyld: Library not loaded: libGVars3-0.6.dylib
    Referenced from: /Users/ajc/_Working/PTAMM/PTAMM/./CameraCalibrator
    Reason: image not found
    Trace/BPT trap: 5

    Which I am assuming is related to the –disable-widgets –without-readline arguments.

    Any suggestions on what could fix this?

    • Just as a touch more detail, I reverted from homebrew to MacPorts, reinstalled dependancies, and got gvars compiling without the –disable-widgets and –without-readline options enabled.

      Still get the same error when trying to run the binaries though:

      ~/_Working/PTAMM/PTAMM$ ./CameraCalibrator
      dyld: Library not loaded: libGVars3-0.6.dylib
      Referenced from: /Users/ajc/_Working/PTAMM/PTAMM/./CameraCalibrator
      Reason: image not found
      Trace/BPT trap: 5

      • Just to clarfiy, I tried all usual things such as

        export DYLD_LIBRARY_PATH=/Users/ajc/local/lib/libGVars3-0.6.dylib

        Before running it which gives a similar, related error:
        dyld: Library not loaded: libGVars3-0.6.dylib
        Referenced from: /Users/ajc/_Working/PTAMM/PTAMM/./CameraCalibrator
        Reason: no suitable image found. Did find:
        /Users/ajc/local/lib/libGVars3-0.6.dylib/libGVars3-0.6.dylib: stat() failed with errno=20

      • I rebuilt clean versions of everything from scratch, and it all seemed to magically work this time. I guess it could have been a hangover from switching from homebrew to macports.

        Can report all working fine here on OSX 10.7.

  6. mattjakob says:

    Hello,
    I am running into this problem after having successfully compiled all the depending libraries (in the correct order) and checking that they’re all working in the destination folder ($(HOME)/local/)

    g++ -g -O3 -arch i386 GLWindow2.cc -o GLWindow2.o -c -I /Users/mattjakob/local/include -D_OSX -D_REENTRANT -m32 -DENABLE_MODELS_GAME
    make: *** No rule to make target `VideoSource_OSX.o', needed by `PTAMM'.  Stop.
    make: *** Waiting for unfinished jobs....
    GLWindow2.cc: In member function ‘void GLWindow2::SetupWindowOrtho()’:
    GLWindow2.cc:117: error: cannot convert ‘CVD::ImageRef’ to ‘GLdouble’ for argument ‘1’ to ‘void glOrtho(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble)’
    make: *** [GLWindow2.o] Error 1
    
    • It looks like you are missing VideoSource_OSX.cc. Have you copied the relevant files from the Build/OSX dir?

      • Mankoff says:

        Hi,

        I have the same error as matt above. However, VideoSourc_OSX.cc was copied from Build/OSX and compiled correctly (I presume, I have a VideoSource_OSX.o file in the current folder).

        If I comment out line 117 of GLWindow2.cc “glOrtho(size());”, then this file compiles, but the build crashes further on with the following:

        g++ -g -O3 -arch i386 SmallBlurryImage.cc -o SmallBlurryImage.o -c -I /Users/mankoff/local/src/PTAM/local/include/ -I/Users/mankoff/local/src/PTAM/ -D_OSX -D_REENTRANT -m32
        SmallBlurryImage.cc: In member function ‘std::pair<TooN::SE2, double> SmallBlurryImage::IteratePosRelToTarget(SmallBlurryImage&, int)’:
        SmallBlurryImage.cc:131: error: ‘transform’ is not a member of ‘CVD’
        make: *** [SmallBlurryImage.o] Error 1

        Thanks for any hints,

        -k.

      • It looks like there is an issue with CVD. As it is not complaining about the header files and building the VideoSource file, CVD is being found. But it appears that it cannot find the transform function (cvd/vision.h), and glOrtho (cvd/gl_helpers.h). Either libCVD has undergone some drastic changes recently (if you are using the latest version) or Xcode is being funny about what it can find. Try placing the appropriate #includes in the files that are causing problems, if they are not there already, and verifying that the functions are in the files I mentioned.

      • mankoff says:

        Those functions do exist in the files you mentioned and were included. I tried re-building with an older libcvd (Mon May 11 16:29:26 BST 2009 as mentioned in the README) with the same result.

  7. Hello
    When trying to compile on os x 10.6.8 libCVD throws me this error in console:

    cvd_src/OSX/qtbuffer.cpp:148: error: ‘vector’ was not declared in this scope
    cvd_src/OSX/qtbuffer.cpp:148: error: expected primary-expression before ‘int’
    cvd_src/OSX/qtbuffer.cpp:148: error: expected `;’ before ‘int’
    cvd_src/OSX/qtbuffer.cpp:151: error: ‘allowedDevices’ was not declared in this scope
    cvd_src/OSX/qtbuffer.cpp:156: error: ‘allowedDevices’ was not declared in this scope
    cvd_src/OSX/qtbuffer.cpp:159: error: ‘allowedDevices’ was not declared in this scope
    cvd_src/OSX/qtbuffer.cpp:191: warning: array subscript has type ‘char’
    make: *** [cvd_src/OSX/qtbuffer.o] Error 1
    make: *** Waiting for unfinished jobs….

    anyone have any suggestions that you can be?

    • Well, vector is just the STL std::vector, so it looks like the header has not been included. I am not sure which version of libCVD you are using, so try the following:

      • Open the qtbuffer.cpp file
      • Add #include <vector> at the top with the other includes.
      • Check that using namespace std; is there too.

      Hopefully that will do the trick. If not you may have other bigger problems.

  8. Peter Boyer says:

    Locked and loaded on Lion with a MacBook Air.

    As mentioned above, I installed all of the dependencies from MacPorts as described in Section 14 of the manual. I then proceeded to follow this document. Note: The latest version of libcvd fixes all the errors above, but, as mentioned in the Joo-Haeng’s comment, you will need to make some small edits. I also had to add #include to qtbuffer.cpp, as in Sebastien’s comment.

    Good luck!

    • Ben says:

      Hi Petter,
      I tried to compile PTAM on my MacBook Pro with Lion 10.7.4. Following all the step above (including the modification of qtbuffer.cpp), I got the error

      ignoring file /Developer/SDKs/MacOSX10.6.sdk/usr/local/lib/libstdc++.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

      Seems libstdc++.dylib dose not support i386 anymore. Did you meet this? What version of Lion are you using? Do you know how to fix this problem? Thank you!

  9. salvatore says:

    Hi, i would like to know if it is possible use PTAMM with the microsoft kinect device? if yes is there any source code that implement this device instead of a normal rgb camera??

    salvo

  10. Ben says:

    Hi Robert,
    I tried to compile PTAM on my MacBook Pro with Lion 10.7.4. Following all the step above (including the modification of qtbuffer.cpp), I got the error

    ignoring file /Developer/SDKs/MacOSX10.6.sdk/usr/local/lib/libstdc++.dylib, file was built for unsupported file format which is not the architecture being linked (i386)

    Seems libstdc++.dylib dose not support i386 anymore. Did you meet this? What version of Lion are you using? Do you know how to fix this problem?

    Could you tell me why we have to compile all things into i386 binary? What’s the problem in using X86_64 arch? Thank you!

    • Ben says:

      Solved. Installed apple-gcc4.2 from MacPort and link the libstdc++.dylib to the installed version.

      But still have one question: Why does PTAM stick on 32bit?

  11. Hassim Garan says:

    I keep on getting an error message “make: *** [src/GUI.0] Error 1” and toons missing gui
    I’m at a loss???

  12. xavier bernasconi says:

    Hi

    I’ve been trying to compile libcvd for a couple of days now..on mac os x 10.8 and Xcode 4.4.1..i think i fixed quite few problems, but I can’t seem to get around these errors:

    cvd_src/videodisplay.cc:56: error: ‘GLX_RGBA’ was not declared in this scope
    cvd_src/videodisplay.cc:57: error: ‘GLX_RED_SIZE’ was not declared in this scope
    cvd_src/videodisplay.cc:58: error: ‘GLX_GREEN_SIZE’ was not declared in this scope
    cvd_src/videodisplay.cc:59: error: ‘GLX_BLUE_SIZE’ was not declared in this scope
    cvd_src/videodisplay.cc:60: error: ‘GLX_DOUBLEBUFFER’ was not declared in this scope
    cvd_src/videodisplay.cc: In member function ‘void CVD::VideoDisplay::init(double, double, double, double, double, int*)’:
    cvd_src/videodisplay.cc:115: error: ‘my_visual’ was not declared in this scope
    cvd_src/videodisplay.cc:115: error: ‘glXChooseVisual’ was not declared in this scope

    I added the mesa port, and added the include path file /opt/local/include

    It fixed the fact that it couldn’t find GL/gl.h and other header files, but unfortunately it didn’t get rid of the errors above.

    Does anyone have any idea on how to fix this problem?

    Cheers

    Xavier

  13. zeta says:

    Does PTAMM work on 64bit 10.8? PTAMM needs the QuickTime framework, but such framework no longer works on 64bit client.

    • zeta says:

      That’s fine. I got it work at 32bit. However, it seems that on Mountain Lion there is no “InitCursor()”, which makes the configure file of libcvd generate a makefile without Carbon and QuickTime support. Hence, removing such function called from the configure file can generate a correct makefile in Mountain Lion.

  14. feng zhang says:

    Hi,
    How to compile PTAMM on Mountain Lion ? Does PTAMM work on 64bit 10.8?

  15. Hi, I’m Sebastian G. Botasi, I’m from La Plata, Buenos Aires, Argentina. Working in a laboratory research and advanced training in computer science. Osx 10.6.8 I have compiled all the necessary libraries for running PTAMM. CameraCalibrator program works well and generates the most camera.cfg file.

    The problem arises when I try to run PTAMM, I get this error in console:

    GV3 :: Register: TooN :: vector Camera.Parameters undefined. Defaults to [0.5 0.75 0.5 0.5 0.1]

    ! Camera.Parameters is not set, need to run the tool CameraCalibrator
    and / or put the line into the Camera.Parameters = Appropriate. cfg file.

    They thought it may be???

    I hope answers from already thank you very much.

  16. Louise Lee says:

    Hi,
    I’m interested in what the red, green, yellow, and blue feature points mean?
    Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s