UPDATE: see this post.
The 4.0 release of the iPhone OS has introduced access to the pixel data of the live camera stream through the AVCaptureDevice class in the AVFoundation framework. Want to use it? OK!
If you want the SUPER SIMPLE way and just want to start playing around immediately, get this version of oF that I fixed up for the 4.0 OS.
http://4u.jeffcrouse.info/of/of_preRelease_v0061_iPhone4_FAT.zip
otherwise (and I recommend it), read on.
NOTE: This is written for OSX/XCode. I have no idea about other platforms.
- Of course, make sure you have the iPhone OS 4.0 and the iPhone version of oF
- Copy the emptyExample and rename it to something else
- You’ll probable have to fix some settings in your new project
- Go to Project > Edit Project Settings
- Change “Base SDK” to iPhone Device 4.0 (this stuff won’t work on anything else – even the 4.0 Simulator)
- I usually have to change the Target settings also. Project > Edit Active Target “Blah”
- Toggle between “release” and “debug” in the build type dropdown to get the frameworks (libs > core > core frameworks) to switch over to 4.0. If they are still red after doing this, something went wrong.
- Add the following frameworks by right-clicking on the “core frameworks” folder and selecting “Add > Existing Frameworks”
- CoreVideo.framework
- CoreMedia.framework
- AVFoundation.framework
- Fix FreeImage
- Easy Way: Replace your libs/FreeImage folder with this one: FreeImage. You’ll have to also remove the existing one from your XCode project and drag this one in.
- Hard Way: Read this in the oF forum
- get ofxiPhoneVidGrabber and put it in your addons folder
- Get the example: iPhoneVidGrabberExample and put it in your apps/[something] folder
- Run and enjoy!
Want to use OpenCV too?
- Add this to your addons folder: ofxOpenCviPhone
- Add this to your apps/iPhoneSpecificExamples folder: openCviPhoneExample
- Run and enjoy!
What happened there?
To use OpenCV, you have to recompile it for arm6. I also added a function to ofxCvColorImage so that you can feed it a 4 channel IplImage* and it will know how to convert it to 3 channels. If this doesn’t make sense to you, you probably shouldn’t read any further. But if you are really curious, here is how I compiled for arm6. I couldn’t figure out the configure flag to leave out JPEG support, so the 5th step is a little ghetto.
- Make a copy of the ofxOpenCV library from the normal oF distribution.
- Get OpenCV 1.0
- expand the file you just downloaded
- crack open a terminal and ‘cd’ to the resulting directory
mkdir build; cd build; ../configure --prefix=/path/to/somewhere/stage --without-imageio --without-python --without-swig --disable-apps --disable-dependency-tracking --without-carbon --without-quicktime --enable-shared --without-gtk --host=arm-apple-darwin10 CXX=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++-4.2 CXXFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk"- Open build/cvconfig.h and change:
#define HAVE_JPEG
to
//#define HAVE_JPEG makemake install- Now the include and lib folders that you need are in
/path/to/somewhere/stage. Replace them with the stuff in the ofxOpenCV that you got from the normal oF distro.
- Here is what I replaced in ofxCvColorImage
void ofxCvColorImage::operator = ( const IplImage* _mom ) { if( _mom->width != width || _mom->height != height || _mom->depth != cvImage->depth) { ofLog(OF_LOG_ERROR, "in =, images need to match in size and depth"); return; } switch(_mom->nChannels) { case 3: cvCopy( _mom, cvImage ); break; case 4: cvCvtColor( _mom, cvImageTemp, CV_RGBA2RGB ); break; case 1: cvCvtColor( _mom, cvImageTemp, CV_GRAY2RGB ); break; default: ofLog(OF_LOG_ERROR, "in =, nChannels not allowed."); return; } swapTemp(); flagImageChanged(); }
Please let me know if there is anything I need to correct here.
6 Comments
hi
i just have a quick question about the recompiled library you uploaded
can i run in parallel the original library and yours ? (i mean without removing the original one to still be able to compile for 3.2)
(please don t be too specific , i might not be able to understand all as i m a beginner )
thank for sharing !
LK
Nice work! Have you tried compiling openCV for armv7? I’m curious if that improves performance on iPhone 3GS and 4.
hi!
I asked about a problem running the sample app on iPhone 4 at the OF forum:
http://www.openframeworks.cc/forum/viewtopic.php?f=25&t=4784
maybe you can have a look on it. thanks!
Hey guys, Sorry you are having trouble with this — this was one of my first forays into Objective C, so I guess I got the pixel mapping wrong.
Does this work for IOS 4.1?
Nice How to! Thanks.
It is the next step to get augmented reality on iphone with openframe work working. dit you know how i can port the ofxARToolkitPlus for the iphone ?