본문 바로가기

아이폰

아이폰 + OpenCV

출처 : http://niw.at/articles/2009/03/14/using-opencv-on-iphone/en

Using OpenCV on iPhone

Posted by Yoshimasa Niwa on 03/14, 2009

OpenCV is a library of computer vision developed by Intel, we can easily detect faces using this library for example. I’d note how to use it with iPhone SDK, including the building scripts and a demo application. Here I attached screen shots from the demo applications.

Support OpenCV 2.0.0 and iPhone SDK 3.x

I updated the script and made patches for OpenCV 2.0.0 and iPhone SDK 3.x! (Updated 11/15/2009)

Getting Started

All source codes and resources are opened and you can get them from my github repository. It includes pre-compiled OpenCV libraries and headers so that you can easily start to test it. If you already have git command, just clone whole repository from github. If not, just take it by zip or tar from download link on github and inflate it.

% git clone git://github.com/niw/iphone_opencv_test.git

After getting source codes, open OpenCVTest.xcodeproj with Xcode, then build it. You will get a demo application on both iPhone Simulator and iPhone device.

Building OpenCV library from source code

You can also make OpenCV library from source code using cross environment compile with gcc. I added some support script so that you can easy to do so. The important point is that iPhone SDK doesn’t support dynamic link like “.framework”. We have to make it as static link library and link it to your application statically.

  1. Getting source code from sourceforge. I tested with OpenCV-2.0.0.tar.bz2.

  2. Extract downloaded archive on the top of project project directory

    % tar xjvf OpenCV-2.0.0.tar.bz2
    
  3. Apply patch for iPhone SDK

    % cd OpenCV-2.0.0
    % patch -p0 < ../cvcalibration.cpp.patch_opencv-2.0.0
    
  4. Following next steps to build OpenCV static library for simulator. All files are installed intoopencv_simulator directory.

    % cd OpenCV-2.0.0
    % mkdir build_simulator
    % cd build_simulator
    % ../../configure_opencv
    % make
    % make install
    
  5. Following next steps to build OpenCV static library for device All files are installed intoopencv_device directory.

    % cd OpenCV-2.0.0
    % mkdir build_device
    % cd build_device
    % ARCH=device ../../configure_opencv
    % make
    % make install
    

Patch and Configure support script

OpenCV 2.0.0 (and also 1.1.0) has a glitch which refuse builing the library with iPhone SDK. You need to apply the patch cvcalibration.cpp.patch so that you can build it.

Congiure support script configure_opencv has some options to build OpenCV with iPhone SDK. Try to --help option to get the all options of it.

Converting images between UIImage and IplImage

OpenCV is using IplImage structure for processing, and iPhone SDK using UIImage object to display it on the screen. This means, we need a converter between UIImage and IplImage. Thankfully, we can do with iPhone SDK APIs.

Creating IplImage from UIImage is like this.

// NOTE you SHOULD cvReleaseImage() for the return value when end of the code.
- (IplImage *)CreateIplImageFromUIImage:(UIImage *)image {
  // Getting CGImage from UIImage
  CGImageRef imageRef = image.CGImage;

  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  // Creating temporal IplImage for drawing
  IplImage *iplimage = cvCreateImage(
    cvSize(image.size.width,image.size.height), IPL_DEPTH_8U, 4
  );
  // Creating CGContext for temporal IplImage
  CGContextRef contextRef = CGBitmapContextCreate(
    iplimage->imageData, iplimage->width, iplimage->height,
    iplimage->depth, iplimage->widthStep,
    colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault
  );
  // Drawing CGImage to CGContext
  CGContextDrawImage(
    contextRef,
    CGRectMake(0, 0, image.size.width, image.size.height),
    imageRef
  );
  CGContextRelease(contextRef);
  CGColorSpaceRelease(colorSpace);

  // Creating result IplImage
  IplImage *ret = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 3);
  cvCvtColor(iplimage, ret, CV_RGBA2BGR);
  cvReleaseImage(&iplimage);

  return ret;
}

Don’t forget release IplImage after using it by cvReleaseImage!

And creating UIImage from IplImage is like this.

// NOTE You should convert color mode as RGB before passing to this function
- (UIImage *)UIImageFromIplImage:(IplImage *)image {
  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  // Allocating the buffer for CGImage
  NSData *data =
    [NSData dataWithBytes:image->imageData length:image->imageSize];
  CGDataProviderRef provider =
    CGDataProviderCreateWithCFData((CFDataRef)data);
  // Creating CGImage from chunk of IplImage
  CGImageRef imageRef = CGImageCreate(
    image->width, image->height,
    image->depth, image->depth * image->nChannels, image->widthStep,
    colorSpace, kCGImageAlphaNone|kCGBitmapByteOrderDefault,
    provider, NULL, false, kCGRenderingIntentDefault
  );
  // Getting UIImage from CGImage
  UIImage *ret = [UIImage imageWithCGImage:imageRef];
  CGImageRelease(imageRef);
  CGDataProviderRelease(provider);
  CGColorSpaceRelease(colorSpace);
  return ret;
}

Ok, now you can enjoy with OpenCV with iPhone!

Frequently Asked Questions

  • I can’t build and run this demo application for iPhone device, I can build and run it on iPhone simulator though… why? I got next error when building.

    ld warning: in /usr/local/lib/libcv.dylib, file is not of required architecture
    ld warning: in /usr/local/lib/libcxcore.dylib, file is not of required architecture
    Undefined symbols:
      "_cvCreateMemStorage", referenced from:
          -[OpenCVTestViewController opencvFaceDetect:] in OpenCVTestViewController.o
      "_cvGetSeqElem", referenced from:
          -[OpenCVTestViewController opencvFaceDetect:] in ......
    
    • Have you ever installed OpenCV for MacOS X? This error is because of the linker using wrong library for MacOS X instead of iPhone device. I solved this problem so that you can now build it for iPhone device. Please git pull or download the package again from github.

Change Log

  • 12/21/2009 - Support Snow Leopard + iPhone SDK 3.1.2, Thank you Hyon!
  • 11/15/2009 - Support OpenCV to 2.0.0 + iPhone SDK 3.x
  • 03/14/2009 - Release this project with OpenCV 1.0.0 + iPhone SDK 2.x

One more thing…

I mentioned that the face detection using OpenCV takes very long time. For example detecting with iPhone screen size image, it takes 10 seconds or more…hmmmm

License

This sample is under MIT License.

Meta

Comments

  • bluestone007 said at 06/21, 2009
    Good!
    Same paper here:

    http://www.computer-vision-software.com/blog/2009/04/opencv-vs-apple-iphone/comment-page-1/#comment-106
  • イグナチオ said at 07/05, 2009
    この情報があると大変助かります、ありがとうございます!。opencvをダウンロードし解凍するとエラーがでますので、恐らく違うopencvのファイルだと思います。
    opencv-1.1pre1.tar.gz の具体的なリンクを教えていただけないでしょうか?
  • Yoshimasa Niwa said at 07/05, 2009
    > イグナチオ さん
    数日前のSourceforgeの改変で、ダウンロードリンクが変更になっており、Safariではダウンロードできなくなっています。opendv-1.1pre1.tar.gzはopencv-linuxの下にありますが、Firefoxを使うなどしてダウンロードしてください。
  • Keo said at 07/29, 2009
    Hi, Great stuff here. I was wondering if you got openCV's video capture api to work?
  • Dongpyo Hong said at 07/29, 2009
    It would be great if you share your sample code
  • Dongpyo Hong said at 07/29, 2009
    Whoops! You did ;-) I didn't realize the bottom link.
  • Yoshimasa Niwa said at 07/31, 2009
    > Keo san
    Hi, unfortunately OpenCV stuff doesn't support any iPhone specific functions includes Camera operations so far.

    > Dongpyo san
    Right! You can grab the sample from my github repository!
  • Ted said at 08/12, 2009
    助かったよ!

    Thanks for providing an example project for this! This is a big help.
  • jeff said at 09/23, 2009
    I got the armv6 to compile, but not the sim. anyone have any trouble with that? the error i get is ** No targets specified and no makefile found. Stop.

    thanks.
  • jeff said at 09/23, 2009
    I think i figured it out. for the sim stuff, you need to make a few changes. see the 4 lines below. I'm running snow leopard + sdk3.1. Snow leopard requires you to change from darwin9 to darwin10. sdk3.1 requires you to change the sdk appropriately (note you don't need this change for arm, since you can still build to target 2.2.1 - minor change from 2.2 to 2.2.1 in the armv6.sh file). Hope that helps folks.
    CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.0.1 \
    CXX=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-g++-4.0.1 \
    CFLAGS="-arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk" \
    CXXFLAGS="-arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk" \


  • asffa said at 09/23, 2009
    jeff, please, where I have to change this?

    CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.0.1 \
    CXX=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-g++-4.0.1 \
    CFLAGS="-arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk" \
    CXXFLAGS="-arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk" \
  • Yoshimasa Niwa said at 09/24, 2009
    > Jeff, asffa
    Thanks, I know current configure file doesn't work with iPhone SDK 3.x (and on Snow Leopard?) Unfortunately I'm quite busy for now, I then can't address this issue.. though it might be helpful! Thanks!
  • dropplent said at 10/01, 2009
    Anyone got a solution?! Yoshimasa please, could you help us?! how can we get it work on 3.1 sdk?
  • Ignacio said at 10/05, 2009
    Hey, If you use Yoshimasa-san 's library you don't need to compile a new opencv library. 
    I would like to know how can I compile opencv 2.0 for iphone?
    I have tried this (based in README file form Yoshimasa-san project) But no success.
    % cd OpenCV-2.0.0
    % mkdir build_armv6
    % pushd build_armv6
    % ../configure_armv6.sh
    % make
    % make install
    It is failing just after I try to run the configure_armv6.sh script.
    It start checking things and ...
    checking for C++ compiler default output file name... 
    configure: error: in `/Users/nacho4d/Downloads/OpenCV-2.0.0/build_armv6':
    configure: error: C++ compiler cannot create executables

  • Ignacio said at 10/05, 2009
    >Jeff
    Can you advice on what changes you did for compiling for the device (build_armv6)
    I am trying this but did not work.

    #!/bin/sh
    PREFIX=`pwd`/`dirname $0`/../opencv_armv6
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
    ../configure --prefix=${PREFIX} \
    --host=arm-apple-darwin \
    --enable-static \
    --disable-shared \
    --without-python \
    --without-ffmpeg \
    --without-1394libs \
    --without-v4l \
    --without-imageio \
    --without-quicktime \
    --without-carbon \
    --without-gtk \
    --without-gthread \
    --disable-apps \
    CC=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.2.1 \
    CXX=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-g++-4.2.1 \
    CFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk" \
    CXXFLAGS="-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk" \
    CPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp \
    CXXCPP=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/cpp \
    AR=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ar

    I got 

    checking for C++ compiler default output file name... 
    configure: error: in `/Users/nacho4d/Downloads/OpenCV-2.0.0/build_armv6':
    configure: error: C++ compiler cannot create executables

  • Yoshimasa Niwa said at 11/14, 2009
    Hi there, I'm updating this project for iPhone OS 3.x and latest SDK with OpenCV 2.0. I'll post new article it, thank you!
  • duongtu said at 11/17, 2009
    Thank you very much! It's great for me ^_^
  • duongtu said at 11/17, 2009
    Hi Yoshimasa,
    After installing success for target simulator, I got an error message when 'make install' with the target device:

    ARCH=device ../configure_opencv GCC_VERISON=4.0 
    make install-exec-hook
    ldconfig
    make[3]: ldconfig: Command not found
    make[3]: [install-exec-hook] Error 127 (ignored)
    test -z "/Users/mac/CodeTemplates/iPhoneVideoPerformance/05.OpenCV/Source/OpenCV-2.0.0/build_device/../opencv_device/lib/pkgconfig" || ../autotools/install-sh -c -d "/Users/mac/CodeTemplates/iPhoneVideoPerformance/05.OpenCV/Source/OpenCV-2.0.0/build_device/../opencv_device/lib/pkgconfig"
    /usr/bin/install -c -m 644 opencv.pc '/Users/mac/CodeTemplates/iPhoneVideoPerformance/05.OpenCV/Source/OpenCV-2.0.0/build_device/../opencv_device/lib/pkgconfig'

  • Yoshimasa Niwa said at 11/17, 2009
    > doungtu
    Hi, As you see on this error message, just ignore it.
    We're not using ldconfig because it is for the dynamic linking of OpenCV, we're using static link because of the iPhone limitation.
  • nao said at 11/17, 2009
    素晴らしいですね。参考にさせてもらいました。こういった情報があると助かります。どうもありがとうございます!
  • Miha said at 11/18, 2009
    Hello Yoshima!
    First thank you sharing your great work because your tutorial among others was most helpful!
    I have question about this comment with method for converting to IplImage (UIImageFromIplImage) when it says: "NOTE You should convert color mode as RGB before passing to this function".
    In my project im converting image first to IplImage, then doing some cv pixel changes and then converting it back to UIImage and show it back on imageView. Problem occurs with colors on that picture (it becomes blue). Like there was some problem with color chanels.
    Regarding to comment about changing RGB color mode is there something I need to call before converting back to UIImage?
    tnx for your reply!
  • Miha said at 11/18, 2009
    I found out that color mode is inverted so its BGR.
    But when I try to convert it back to RGB it doesnt work :(
  • Miha said at 11/19, 2009
    Okey I manage to figure out the problem. I had to call the same convertion as in "CreateIplImageFromUIImage" method.
    "cvCvtColor(image, image2, CV_RGBA2BGR);".
    BTW why do we need to transform colors at all?
  • Yoshimasa Niwa said at 11/20, 2009
    > Miha
    Hi, Miha. Yes, you can use cvCvtColor() because we're getting UIImage from CGImage and CGImageCreate requires the RGBA or ARGB formatted byte array. see "Color Spaces and Bitmap Layout" section of "Quartz 2D Programming Guide"
  • Miha said at 11/24, 2009
    Tnx, it makes sense now!
    In my project im doing some body detection and i need to allocate edge (figure) of body.
    Do you maybe know how can i get position of body (figure)?
  • Parsa said at 11/24, 2009
    Is it possible to do anything in realtime yet ? I don't mean the CPU or RAM can handle it, I mean does the OS let you do this ?

    Thanks for your great article, Yoshimasa.
  • Jason Charles said at 11/24, 2009
    Hi, Thanks for your the pre-compiled OpenCV 2.0.0. 

    When I try to build your demo app I get an error saying the following files are missing:-

    cxoperations.hpp, cxmat.hpp, cxflann.h.

    Thank you
  • Yoshimasa Niwa said at 11/28, 2009
    > Miha
    You have to make some training data for detecting specific objects by Open CV. Try to google "haar training".

    > Parsa
    I think somebody is making a patch to increase the speed to detect on iPhone and I hope it works in realtime.

    > Jason
    Weird... Could you try to clone from github to another directory then build it?
  • Daniel Siders said at 12/04, 2009
    Has anyone tried using this with live video and reference frames instead of still images?
  • Giacomo Rizzi said at 12/11, 2009
    GREAT! thank you so much for this porting!

    Little question: how would you do to port OpenSurf to iPhone??
    I think it would be nice to see it in action on the device since the OpenSurf output is slightly different from the OpenCv one..

    Best
    link to OpenSurf: http://code.google.com/p/opensurf1/
  • John Howard said at 12/12, 2009
    First off great work this really helps. Second has anyone run into the problem that the configure file fails to execute "fails sanity check?". The log file says that there was an error running conftest.cpp "bad value (core2) for -mtune= switch". I don't know why this would be a bad value, I am on an Intel Xeon which is a dual core machine. Thanks in advance for the help.

  • maplevincent said at 12/13, 2009
    jeff said at 09/23, 2009
    I got the armv6 to compile, but not the sim. anyone have any trouble with that? the error i get is ** No targets specified and no makefile found. Stop.

    Hi, I got the same problem when I tried to do the "make" here:

    % cd OpenCV-2.0.0
    % mkdir build_simulator
    % ../../configure_opencv
    % make
    % make install

    Has anyone know how to solve this problem? (and I didn't see the Makefile in the downloaded codes......)

    Thanks!
  • Kevin Cain said at 12/21, 2009
    I need a different variant than the ones discussed above: opencv1.1+SDK 3.x.

    I successfully built the opencv2.0+SDK 3.x project, but with opencv1.1 build, I made the following changes to 'configure_opencv', similar to 'jeff' above:

    CC=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2 \
    CXX=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-g++-4.2 \
    CFLAGS="-arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk" \
    CXXFLAGS="-arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk" \

    This allows me to 'make' the simulator build, but fails during the subsequent 'make install'

    Can anyone confirm that it is possible to build opencv1.1 with SDK 3.x?

    Thanks!
  • Kevin Cain said at 12/21, 2009
    Just a simple note for maplevincent:

    I think the steps laid out by Yoshimasa-san omit a 'cd' instruction, which I found was necessary to make the project. The added line is below:

    % cd OpenCV-2.0.0
    % mkdir build_simulator
    --> % cd build_simulator
    % ../../configure_opencv
    % make
    % make install
  • Yoshimasa Niwa said at 12/21, 2009
    Hi, Kevin, and All users:
    Thank you for your comment! Yes, it is my mistake. I'd update the article in English(it is correct in Japanese).
    And for Snow Leopard users, current script doesn't work on Snow Leopard. I'd also fix it soon!
  • Yoshimasa Niwa said at 12/21, 2009
    Hi John,
    I fixed the issue you pointed out at that comment. Please use the latest source at github repository!

    Hi All,
    I changed my typo and mistakes on the article and update the source code to support Snow Leopard. If you have some trouble on Snow Leopard when configuring OpenCV on it, please update the script from github.

    Thank you!
  • Kevin Cain said at 12/21, 2009
    Hello, Yoshimasa,

    Thanks for updating your source, and marking that small change I noted. There's another small error in your instructions for the device build:

    % ARCH=device ../../configure_opencv 

    should be:

    % ../../configure_opencv ARCH=device

    as below:

    % cd OpenCV-2.0.0
    % mkdir build_device
    % cd build_device
    % ../../configure_opencv ARCH=device 
    % make
    % make install
  • Kevin Cain said at 12/21, 2009
    Thanks again for the new project updates, but I'm still unable to build with opencv1.1+SDK 3.x. on Snow Leopard.

    I have a feeling that it has to do with:

    ARCH_HOST=i686-apple-darwin9

    But changing to 'ARCH_HOST=i686-apple-darwin10' doesn't seem to help.

    Thanks,

    -Kevin
  • Yoshimasa Niwa said at 12/21, 2009
    Hi Giacomo,
    I tested on iPhone then OpenSURF works on my iPhone 3G though, it is super slow...
  • Yoshimasa Niwa said at 12/21, 2009
    Hi Kevin,
    My current configure helper may not support OpenCV 1.1. The older configure script which you can fetch from my github repository may help your problem.
  • Nico said at 12/21, 2009
    Hello!
    I could successfully compile the libraries, and even got a step further and compiled them into a universal lib.

    My question is, how can I start a project from scratch using OpenCV? I looked into the sample project you provide but can't find any pointers to where to configure OpenCV. I find myself with this errors after compiling:

    Undefined symbols:
    "_cvMinAreaRect2", referenced from:
    _cvMinAreaRect in HelloOpenCVAppDelegate.o

    I think the are due to the library not being found, which leads me to the question: how to configure opencv properly in xcode?

    Thanks in advance!
  • Kevin Cain said at 12/22, 2009
    Thanks again for such a fast reply, I will have a look for your earlier github entries for a configuration script which can work with openCV 1.1pre.

    I realize that openCV 1.1pre is a little old, and would rather build around 2.0, of course. If I'm lucky, I will be able to.

    Thanks again,

    -Kevin
  • Kenny said at 12/23, 2009
    Hello, Yoshimasa,
    Thanks for your nice instructions about compiling opencv libs.
    The opencv libs I build are working good on both device and simulator, but there are 7 warnings like the one below.

    ld: warning: can't add line info to anonymous symbol __ZN2cv9ExceptionD1Ev.lsda from ./opencv_simulator/lib/libcxcore.a(lib_cxcore_la-cxmathfuncs.o)

    Is there any way I can do to fix this kind of warning?
    p.s. I am using Snow leopard, and the latest version of script from github
    Thanks in advance!
  • Yoshimasa Niwa said at 12/24, 2009
    Hi Kenny, You can ignore any warnings.
  • Kenny said at 12/24, 2009
    Thanks for your fast reply!
    This article really help me a lot
  • Hamken100per said at 12/25, 2009
    とても助かりました。ありがとうございました。
    HighguiのVideo writer関連が使えるかな、と思って試してみましたが、やっぱり無理でした。
  • Yoshimasa Niwa said at 12/25, 2009
    > Hamken100perさん
    そうですねー、そのあたりすこし頑張ればできると思っていますが、がんばらないとダメですね。そもそもAPIがまだ公式ではないので、なんとも言い難いところがありますが。
  • Forrest said at 01/20, 2010
    So great example !
    Is that legal to publish application to appStore using opencv library in iPhone ?

    There are some camera applications in appStore now, does that can use opencv library now ? what sort of pop framework used there ?
  • Forrest said at 01/20, 2010
    A really awesome project !

    Are there any published apps from app store which is based on opencv ?

    How about the performance ? Is that very slow speed ? 

    welcome further communication 
    forrest.shi < at > gmail < dot > com
  • Yoshimasa Niwa said at 01/23, 2010
    > Forrest
    Yes, you can use it on AppStore. Before asking here like you've commented on, I think you had better try this demo out.
  • Kenny said at 01/23, 2010
    I am a newbie to Mac world.
    I would like to ask where should I extract the tar file? After extract, and run the patch command, it says there is no such directory.
    (Maybe this is a stupid question :P )
  • Yoshimasa Niwa said at 01/24, 2010
    > Kenny
    Hi, you should get this demo project from github then move its directry then extract OpenCV there and move into OpenCV directory then run the patch command though, I think you don't need to apply patch to OpenCV. you can use pre-compiled binaries of OpenCV I included into this demo project. Just open the project with XCode.
  • Jason said at 01/29, 2010
    Hi Yoshimasa, your demo is awesome, really!!



    I tried to build the files from source for the simulator and i get the following at the end:



    configure: error: in `/Users/jasan/Apps/Test1/OpenCV-2.0.0/build_simulator':

    configure: error: C++ compiler cannot create executables



    is there anything i am missing? thanks

  • Jason said at 01/29, 2010
    PS: I checked the config.log and everything is ok, except for:

    conftest.cpp:11:19: error: no include path in wich to search for stdio.h 

    ...



    after that it gives error in some I/O operations

    i know this has nothing to do with your script, but if someone have any clue please help me. thanks.
  • NK said at 01/29, 2010
    Very good example it is really helpful for understanding
  • Kenny said at 01/30, 2010
    Yoshimasa,

    Thanks much. I have downloaded and tested the demo. That's great. I am now learning what the code is doing :P



    If I write my own apps with your lib. Is that OK?
  • Yoshimasa Niwa said at 02/13, 2010
    > Jason
    I'll see some issues with newer SDKs and current project files.

    > NK
    Enjoy!

    > Kenny
    Of course, Yes. This demo app is under MIT license so that you can use my demo codes in your app with the license texts.
    But be careful, OpenCV itself is under BSD license. It's almost same as MIT one though, you had better check these licenses.
  • San said at 02/16, 2010
    Have you tried the -mthumb setting or any of the other ones from this old configuration: http://lambdajive.wordpress.com/2008/12/20/cross-compiling-for-iphone/

    My understanding is thumb can make a big performance difference. There are also alternative math libraries out there that can help device performance.
  • Jared said at 02/17, 2010
    Hey Yoshimasa. Thanks for sharing all the info.

    I have successfully run thru the install process on a newly-created UIView-based iPhone app.

    The directory structure of my xCode project seems to mirror that of the provided demo app, with opencv_device and _simulator dirs in the right place and containing similar files.

    Now I find myself in the same boat as Nico above, however. I want to build with this stuff but can't get the library to come up in a new app. It's breaking at the import:

    #import <opencv/cv.h>
    error: opencv/cv.h: no such file or directory

    I feel like I'm missing something basic in how I might use this stuff in my own apps and am hoping someone can point me in the right direction.

    I'm on OS 10.5.7, xCode 3.1.4 and building for simulator and device v. 3.1.3.

    Any help would be greatly appreciated.
  • Jared said at 02/17, 2010
    I should also say that I've never used an external library like this before.

    As such it's possible that my trouble has less to do with your code and more to do with my lack of experience with linking static libraries into iPhone apps.

    In either case, I could really use some pointers to resources that might illuminate some of this stuff for me.

    Thanks again.
  • Jared said at 02/18, 2010
    Problem solved - it WAS my inexperience with library linking. 

    Breadcrumbs for fellow newbs:

    I pulled the sample archive (niw-iphone_opencv_test...) as a zip from github.

    Step 1: 
    Did the download/extraction of OpenCV-2.0.0 archive thru Safari/Finder.

    Step 2:
    Copied OpenCV-2.0.0 directory into a new xCode project.

    Copied the scripts from the sample archive (niw-iphone_opencv_test...):
    configure_opencv
    cvcalibration.cpp.patch_opencv-1.1.0
    cvcalibration.cpp.patch_opencv-2.0.0
    into the top level of the new xCode Project

    Step 3:
    Worked like a champ.

    Step 4:
    Failed at line 4.
    Had to add CONFIGURE environment variable:
    % CONFIGURE=../configure
    % export CONFIGURE
    Everything got back on track after that.

    Step 5:
    Same as step 4.

    I'm adding Step 6 here:
    Set up build settings in xCode. For reference, take a look at the build settings for the OpenCVTest target in the sample (niw-iphone_opencv_test...) xCode project.

    The first edit is under Linking:Other Linker Flags
    If you're working from a new xCode project, it'll probably be blank. Click it, then click the bottom-left-sprockety-looking button in the info pane (xCode 3.1.4), and select 'Add Build Setting Condition.' Make one for simulator, one for device, and copy the contents for each over from the sample project's settings.

    The second edit is under Search Paths:Header Search Paths
    Add build conditions and copy the contents over from the sample as you did for Other Linker Flags.

    Everything seems to work fine after all that. I've pulled in chunks of code from the sample and have successfully built to device OS 3.1.3 and simulator OS 3.1.3.

    So hopefully that helps others thru some of the more arcane parts of the process.

    And thanks again, Yoshimasa for the sample app and install scripts!
  • Robert said at 02/19, 2010
    Hi, I am using your lib. However, when I tried to use cvvConvertImage and I have included the highgui.h, it gave me "symbol not found" error. I tried it on your test app and I got the same error. Do you happen to know what the problem is and how to fix it?

    Thank you.
  • Robert said at 02/19, 2010
    I could guess the problem about cvvConvertImage is that highgui is not compiled completely because most of the functions in highgui are set to "without-". I managed to find the source file of cvConvertImage and add it to my project. With little modifying, it can be compiled with my project and I finally can use cvConvertImage in my project.

    Cheers~~
  • Yoshimasa Niwa said at 02/22, 2010
    > San
    Mmm, I'll try it later.

    > Jared
    Thank you for your notes, it must be helpful :)

    > Robert
    Good to hear the tip!
  • cheyne said at 02/27, 2010


    I had the same problem with :

    Undefined symbols:
    "_cvMinAreaRect2", referenced from:
    _cvMinAreaRect in HelloOpenCVAppDelegate.o

    I set the valid architecture to just i386 (removed the ppc and 64 bit ones) and problem solved.

  • Jason said at 03/02, 2010
    Hi, i succesfully used OpenCv compiled files on simulator, but only in 10.5.8 i would like to know if there is any change to use it in 10.6.

    Thanks, Jason.
  • Michael said at 03/04, 2010
    Thanks very much for making this tutorial and demo code available! 

    Now that video is available via the official iPhone SDK, it might be very useful to extend / enhance the demo into using a live steam and not just a static photo. I'm guessing that it is possible, and I'm hoping (& crossing my fingers) that I won't be the developer that ends up actually having to do it on the iPhone for the first time. :-) Thanks again.

    p.s. Jason, I've compiled the OpenCV files for the simulator and device just fine under 10.6.2.
  • Jason said at 03/08, 2010
    Michael that's great!!! i used the files in the demo, the compiled ones, but they don't work on 10.6. Obviously i'll have to compile them but i don't know why i've done the steps and i get som errors.
    Michael it would be very much to ask if you could make public the compiled files and the headers? For the simulator and device?
    Thanks very much.
  • Yoshimasa Niwa said at 03/14, 2010
    Video w/iPhone SDK... I don't want to say a lot about it because of NDA. We don't talk about it while it is beta. but in future, I'll do some for it.

    All questions and requests on comment and/or email -- I'm just relocating to San Francisco then my daily life is dramatically changing. I'm slightly busy so all responses will be delay. thank you for waiting!
  • oqto said at 03/21, 2010
    thanxxxx
  • andreasv said at 03/21, 2010
    HI!
    Thanks for everything first of all! Great blog!

    I am working on a project from scratch. My problem is that:

    First of all i have to say i am new to the platform

    I got the 2 folders (opencv_simulator, opencv_device) from Yoshimasa Niwa (THANKS!!!!!!!) and placed them in my XCode project directory. I created some basic Controllers that use opencv in my project.

    My problem is, as i believe, on the linking of the library (step 6).

    I am trying to find out the build properties details of target on Yoshimasa's project but i can not. I can not find the link and search paths mentioned above by Jared. I do not know why... I am selecting Target in Group and Files section in XCode. Then Project ->Edit Project Settings. I still can not find the the Search and Link paths. iS like an empty project...

    Can anybody please copy paste here these lines???

    After that everything should work perfect?


    Thanks in advance....
  • Jasson said at 03/27, 2010
    [andreasv]:
    Don't worry, i've been there. I give you the steps:
    1. Go to your Target item in XCode
    It has the name of your project, its under the Group Targets.

    2. Double click it. Left click.
    You will get a window named Target "your project name" Info

    3.In that new window go tu the Build Tab.
    And ther you have or the linking stuff,paths for headers etc..

  • Ignacio said at 04/07, 2010
    Niwa-san
    This info is sooo useful!, thanks;)
    This is no iphone related but... I wonder If you know how to create an OpenCV universal framework from svn repository source? I could compile and get dylibs from source but how do I build a framework?何かのアドバイスを頂けたら大変嬉しいです。
  • Cliff said at 04/07, 2010
    These instructions do not seem to work for OpenCV 2.1. Any ideas?
  • alejandro said at 04/14, 2010
    Niwa-san
    Thanks for the info, thank you very much!! :)
    i just discover this theme (i know what is opencv and i used it) recently i bought an ipod touch and of course began to think if this is possible to do until i saw the answer here, i just want to ask, to do all this i need a MAC computer or can i do it using ubuntu or windows?

    sorry if the question is to naive, but i'm to fresh about this theme.