zoukankan      html  css  js  c++  java
  • opencv face detect demo (转载)

    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 iOS SDK, including the building scripts and a demo application. Here I attached screen shots from the demo applications.

    Support Latest OpenCV and iOS SDK

    Updated the project, support OpenCV 2.2.0, iOS SDK 4.3, Xcode 4 (Updated 04/17/2011.)

    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 iOS 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. Building OpenCV requiers CMake. You can easily install it by using Homebrew or MacPorts.

      # Using Homebrew % brew install cmake # Using MacPorts % sudo port install cmake -gui 

      If you’ve already installed recent Java update, you may be asked to installjavadeveloper_10.6_10m3261.dmg. This is weird but cmake needs jni.h which is removed from recent Java update, you can download it from here for Mac OS X 10.6 which may require you to subscribe Apple Developer Connection. Yes, Apple is now going to deprecate Java on MacOS X (Updated 10/30/2010).

    2. Getting source code from sourceforge. I tested with OpenCV-2.2.0.tar.bz2.

    3. Extract downloaded archive on the top of demo project directory

      % tar xjvf OpenCV-2.2.0.tar.bz2 
    4. Apply patch for iOS SDK

      % cd OpenCV-2.2.0 % patch -p1 < ../OpenCV-2.2.0.patch 
    5. Following next steps to build OpenCV static library for simulator. All files are installed intoopencv_simulator directory. When running make command, you’ve better assign -j option and number according to number of your CPU cores. Without -j option, it takes a long time.

      % cd .. # Back to the top of demo project directory. % mkdir build_simulator % cd build_simulator % ../opencv_cmake.sh Simulator ../OpenCV-2.2.0 % make -j 4 % make install 
    6. Following next steps to build OpenCV static library for device All files are installed intoopencv_device directory.

      % cd .. # Back to the top of demo project directory. % mkdir build_device % cd build_device % ../opencv_cmake.sh Device ../OpenCV-2.2.0 % make -j 4 % make install 

    Build support script

    Build support script opencv_cmake.sh has some options to build OpenCV with iOS SDK. Try --helpoption to get the all options of it.

    Converting images between UIImage and IplImage

    OpenCV is using IplImage structure for processing, and iOS 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 iOS 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!

    Using OpenCV library in your own project

    The demo application which you can download from my repository is well configured to use these libraries. If you wanted to use OpenCV libraries on your own project, you should need to adding next configurations on it. You can see these settings on the Xcode project of this demo application.

    • Add libopencv_core.a etc, from OpenCV lib directory for either simulators or devices. Actually Xcode doesn’t care which one is for devices or simulators at this point because it is selected by the library search path.
    • Add Accelerate.framework which is used internally from OpenCV library.
    • Select your active build target, then open the build tab in the info panel by Get Info menu.
      • Add -lstdc++ and -lz to Other Linker Flags
      • Add path to OpenCV include directory to Header Search Paths for both simulators and devices.
      • Add path to OpenCV lib directory to Library Search Paths for both simulators and devices.

    Change Log

    • 04/17/2011 - Support OpenCV 2.2.0 + iOS SDK 4.3 + Xcode 4, Thank you for all your comments!
    • 10/30/2010 - Updates for recent changes on the repository and the development environment, Thank you for your comments!
    • 08/22/2010 - Support OpenCV 2.1.0 + iOS SDK 4.0
    • 12/21/2009 - Support Snow Leopard + iPhone SDK 3.1.2, Thank you Hyon!
    • 11/15/2009 - Support OpenCV 2.0.0 + iPhone SDK 3.x
    • 03/14/2009 - Release this project with OpenCV 1.0.0 + iPhone SDK 2.x

    Donation

    If you would like to help this project, please feel free to donate via PayPal using the followin form. Thank you for your donation!

    Amount in USD  

    License

    This sample is under MIT License.

    Share

    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
      % http://www.cnblogs.com/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
      % http://www.cnblogs.com/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 http://www.cnblogs.com/configure_opencv 

      should be:

      % http://www.cnblogs.com/configure_opencv ARCH=device

      as below:

      % cd OpenCV-2.0.0
      % mkdir build_device
      % cd build_device
      % http://www.cnblogs.com/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.
    • Forrest said at 04/25, 2010
      I just wonder if there is existing xcode template for this ? And I want to put this together with three20, which has provide xcode template , really cool. If not , I will do it myself. welcome for talking with skype . (my account is forrest.shi )
    • Jason said at 05/10, 2010
      Hi Yoshimasa, thanks to you, i could finally use opencv in a full project, and build a release.
      Thanks a lot!!!
    • Mithun said at 05/14, 2010
      Hello,

      I am writing an application to create a movie file from a bunch of images on an iPhone. I am using OpenCv. I downloaded openCv static libraries for arm(iPhones native instruction architecture) and the libraries were generated just fine. There were no problems linking to them libraries.

      As a first step, i was trying to create a .avi file using one image, to see if it works. But 
      cvCreateVideoWriter always returns me a NULL value. I did some searchin and i believe its due to the codec not being present. I am trying this on the iPhone simulator. this is what i do...



      - (void)viewDidLoad {
      [super viewDidLoad];
      UIImage *anImage = [UIImage imageNamed:@"1.jpg"];
      IplImage *img_color = [self CreateIplImageFromUIImage:anImage];
      //The image gets created just fine

      CvVideoWriter *writer = cvCreateVideoWriter("out.avi",CV_FOURCC('P','I','M','1'), 25,cvSize(320,480),1);
      //writer is always null

      int result = cvWriteFrame(writer, img_color);
      NSLog(@"\n%d",result);
      //hence this is also 0 all the time
      cvReleaseVideoWriter(&writer);

      }

      I am not sure about the the second parameter. What sort of codec or what exactly it does...
      I am a n00B in this. Any suggestions?
    • doctorhsly said at 05/21, 2010
      Hi Yoshimasa, thanks to you,but i am not clearly for "Patch and Configure support script", i have done above all,but when i want to import <opencv/cv.h> and complie it, error for "no such file", how can i slove it?
    • Yoshimasa Niwa said at 05/31, 2010
      Hi guys, sorry for my late reply... It were slightly busy days!

      > cheyne
      intrigue, actually iPhone SDK 3.x with specified options can't build up the library w/o any patch. I'll see it later.

      > andreasv & Jasson
      Thank you for your comment, I should update this documents more clear later...

      > Ignacio
      You can, but you can't use it on the device because the sandbox on iPhone OS device can't allow you to use any dynamic linking like Framework.

      > alejandro
      Yes, any iPhone SDK needs MacOS X 10.6 and it requires, of course, Mac. I know someone who are doing something on linux box though.

      > Forrest
      It is not template but you can grab my demo application and modify it to what you want to do... it's under MIT license!

      > Jason
      Congratulations! If you don't mind, let me know the application name so that I can enjoy your app :)

      > Mithun
      I guess you need to link another library when you're building OpenCV like ffmpeg. OpenCV itself must not have any ability to generate some movie formats.

      > doctorhsly
      Hi! I guess you need to place opencv directory to the correct place which Xcode can see from the include path. check your include path in the panel which you can get from "Get Info" menu on project or target item.
    • Hang said at 06/03, 2010
      Hi Yoshimasa, 

      I am writing an image processing application. It work fine to run your sample application (face-detect). But when i try the cvSmooth function, it seem not work as expected. Below is my code, could you help on it? Thanks.

      cvSetErrMode(CV_ErrModeParent);

      IplImage *image = [self CreateIplImageFromUIImage:imageView.image];
      IplImage *smoothImage = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);

      //cvSmooth(image, smoothImage, CV_MEDIAN, 3, 0, 0, 0);
      cvSmooth(image, smoothImage, CV_BILATERAL, 3, 3, 0.01, 0.003);
      //cvSmooth(image, smoothImage, CV_GAUSSIAN, 3, 0, 0, 0);

      imageView.image = [self UIImageFromIplImage:smoothImage];

      cvReleaseImage(&image);
      cvReleaseImage(&smoothImage);

      [self hideProgressIndicator];

      I'm tried to use different parameter for cvSmooth, but all return the same result. Any suggestion?
      Thanks.
    • Jason said at 06/04, 2010
      Well here i am again. Yoshimas thanks to you my team have our first OpenCV included iPhone app on the AppStore. It uses automatic face detection, image processing, smooth, blend, filters.. all
      You get big credit here. If any one wants to check it out go to http://itunes.apple.com/app/flags-faces/id371891114?mt=8

      Flags&Faces Support your team from your iPhone!!!
      Thanks again!!
    • Diego said at 06/21, 2010
      Any chance you could update this blog post to make it work with OpenCV 2.1?? That would be terrific!

      Thanks

      Diego
    • Jai Pillai said at 07/06, 2010
      Nice work, will try on my iphone....
    • Diziet said at 07/10, 2010
      A few minor tweaks and it worked fine for me in OSX/XCode 3.2.3. I had to add a disable-openmp due to linker errors but that was the only major headache. Modifed the script to leave symbols intact for simulator packages and stripped for device also.

      Thank you thank you thank you!
    • キム・テウ said at 07/21, 2010
      "http://www.cnblogs.com/configure_opencv"をしたら、次のようになりました。

      checking whether make sets $(MAKE)... yes
      checking whether make sets $(MAKE)... (cached) yes
      checking for style of include used by make... GNU
      checking for C++ compiler default output file name... 
      configure: error: in `/Users/lent27/Package/iphone_opencv_test/OpenCV-2.0.0/build_simulator':
      configure: error: C++ compiler cannot create executables
      See `config.log' for more details.

      "config.log"を見ましたが、なにがなんだかわかりません。versionや設定などは全部同じです。
    • ueno said at 08/11, 2010
      iPhoneで、OpenCVを使用したいと思いまして、参考にさせていただきました。が、インストール途中の、http://www.cnblogs.com/configure_opencvを実行したところで、下記の様になり、先に進めません。


      ---> Computing dependencies for zlib
      ---> Cleaning zlib
      ueno-gi-no-macbook-pro:build_simulator ueno$ http://www.cnblogs.com/configure_opencv
      Use iPhone SDK 3.1.2(gcc 4.2) for simulator
      checking build system type... i686-apple-darwin
      checking host system type... i686-apple-darwin9
      checking target system type... i686-apple-darwin9
      checking for a BSD-compatible install... /usr/bin/install -c
      checking whether build environment is sane... yes
      checking for i686-apple-darwin9-strip... no
      checking for strip... strip
      configure: WARNING: using cross tools not prefixed with host triplet
      checking for a thread-safe mkdir -p... ../autotools/install-sh -c -d
      checking for gawk... no
      checking for mawk... no
      checking for nawk... no
      checking for awk... awk
      checking whether make sets $(MAKE)... yes
      checking whether make sets $(MAKE)... (cached) yes
      checking for style of include used by make... GNU
      checking for C++ compiler default output file name... 
      configure: error: in `/Users/hoge/iPhone/niw-iphone/OpenCV-2.0.0/build_simulator':
      configure: error: C++ compiler cannot create executables
      See `config.log' for more details.

      何か私の方で足りない事がありますでしょうか。
      または、gitよりDLしたファイルに最初からあるopencv_simulatorとopencv_deviceフォルダごと、自分のプロジェクトに追加すれば良いのか?と思い、試してみたのですが、ビルドでエラーになってしまいました。

      ご教授お願い致します。
    • Yoshimasa Niwa said at 08/12, 2010
      iPhone SDK、OpenCVそれぞれのバージョンアップについていけていません。特にOpenCVはビルド方法が異なるので厄介です。追々、それぞれに対応していきたいと思いますが、今暫くお待ち下さい。
    • nonnus said at 08/14, 2010
      hi, just found about opencv and its possibilities seem impressive !
      i am trying to use it to achieve motion tracking on ios4, so far it seems i could got opencv running on my own project without much issues using the folders from test project,
      however even without further processing it seems to run out of memory just by using your methods to swap between UIImage and IplImage after some frames...

      fyi, i am cvReleaseing the IplImage, so thats not the issue.
      i am doing processing on alternate queue and i am not really sure if the imageFromCGImage: method used is thread safe so it migth be the problem

      this is currently stopping me from making further advances for now in propper processing so any suggestion is welcome :)

      abracos

      nonnus

      ps: i would also like to mention that the sample project on git hub seemed to be leaking
    • nonnus said at 08/15, 2010
      back again, 
      as i expected problems seemed to be related to threading,
      seem to be fixed now...

      spent some time experimenting with motion tracking but still havent found an accurate algorithm

      also played with face detection wich seem too slow for real time on iphone it seems, even if i cap sampling to 15 fps)

      nonnus
    • Nathaniel Lewis said at 08/17, 2010
      Just downloaded the source package. This is very, very cool. I have been trying for a few weeks now to get this working and when I cam across this and the fact that it worked for iOS 4 is making my project plenty easier.
    • Yoshimasa Niwa said at 08/22, 2010
      皆様、iOS SDK 4.0とOpenCV 2.1に対応させました。アプリケーション自体は変更ありません。Githubから最新版をpullしてください。

      Hi there, I just updated this article to support latest OpenCV 2.1 and iOS SDK 4.0. Update code from github by git-pull then enjoy! :)
    • Ashish Lal said at 08/22, 2010
      Thanks! Awesome work. Very helpful. The simulator build went fine. But the device build gives some errors. Any ideas?

      /Users/MY/Downloads/OpenCV-2.1.0/build_device/CMakeFiles/CMakeTmp/testCCompiler.c:1:
      error: -mmacosx-version-min not allowed with -miphoneos-version-min

      make[1]: *** [CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o] Error 1

      make: *** [cmTryCompileExec/fast] Error 2

      CMake will not be able to correctly generate this project.
      Call Stack (most recent call first):
      CMakeLists.txt:39 (project)


      -- Configuring incomplete, errors occurred!
    • Yoshimasa Niwa said at 08/22, 2010
      Ahish Lal: Remove build_device dir then try again, I guess cmake is caching the settings for simulator.
    • Ashish Lal said at 08/22, 2010
      No it didnt work. But I will fix it later. Working on something else right now. Appreciate this work very much.
    • Yoshimasa Niwa said at 08/22, 2010
      Weird, update CMake, make sure OpenCV version or CMake related settings. It seems to be an error from CMake which try to build a binary for MacOS X instead iOS.
    • calven said at 08/24, 2010
      Thanks for posting this project!

      I just downloaded the test project and copied the built opencv libraries into my own project. I am using OS 10.6.4 and xcode 3.2.3 and if you are having troubles compiling your project follow Jared's instructions about the two edits (1-linking, 2-search paths). basically, make sure that those settings in your project match the settings in the sample project and it should build fine.
    • affogato said at 08/31, 2010
      Yoshimasa, thank you very much for this sample project, it is fantastic.

      In the last update, you include the 'device' static libraries directly in the project. Therefore, the device specific library is used even for the simulator (i think). 

      Why did you do it that way, instead of including the device/simulator libraries in the project settings under the 'other linker flags' for the appropriate case (i.e. simulator or device), as you had done previously.
    • Yoshimasa Niwa said at 08/31, 2010
      affogato: Hi, Good point. Xcode is just passing -l(libname) like -lcxcore from library path in the project tree. so, whichever it should work fine, at least on my Xcode. If you saw some issues on it, let me know the details. Thanks!
    • marcof said at 09/01, 2010
      Hi Yoshimasa, great work!
      I just wanted to know how it was possible to use the new C++ interface introduced in OpenCV 2.0 (templates, Mat...). It is much more convenient to use. But I guess the compiler won't take any C++ function in the .m files, will it?
    • Yoshimasa Niwa said at 09/02, 2010
      marcof: we can use C++ with Objective-C, we need to use .mm instead though. See "Using C++ With Objective-C" in the Apple documentations.
    • Tal said at 09/02, 2010
      Hi, Yoshimasa
      I have a small problem which I hope you’ll be able to answer.
      Whenever I move/copy the directory in which the project is located, the moved/copied project does not compile.
      I have been trying to figure out a sensible reason as to why this would happen for awhile, and can’t find one.
      My question is, will I be able to transfer the app to a physical device and have it work properly? And if not, how should I go about fixing this issue?
      Thanks in advance.

      PS.
      You really helped me and my partner in developing our app. This is the only useful thread we found on the net concerning openCV on the iPhone. Thanks a lot =)
    • Tal said at 09/03, 2010
      Hi Yoshimasa
      Nevermind the last question I got it working =)
      Although now I have another question...
      I tried to change the project's name after I did all of the steps you mentioned, but now it doesn't recognize OpenCV anymore. I used Xcode's "Rename" function under "Project" in the menu bar. Also, will it really take OpenCV 10 seconds to detect the face on a real iPhone? Because on my computer it's almost instantaneous. Thanks in advance.
    • Yoshimasa Niwa said at 09/03, 2010
      Tal: Please make sure all path related stuff in the settings of your Xcode project and the builds, then speed. Imagine how your Mac is faster than iPhone CPU...! Though, on Github, some contributor has made the fork to improve the speed of it, you can try it.
    • Roman said at 09/04, 2010
      Hi Yoshimasa,
      You mentioned a fork that improves the speed and is located on GitHub. I couldn't figure out which fork it is - do you have the URL?

      Thanks for all this work!
      Roman
    • Eric said at 09/06, 2010
      Hi Yoshimasa,

      I noticed that in opencv_cmake.sh, you set ARCH="armv6", but iPhones 3GS and 4 are armv7. Would building for armv7 improve performance?
    • Yoshimasa Niwa said at 09/06, 2010
      Eric: opencv_cmake.sh overwrite that environment variable. If you wanted to specify armv7, you need to edit the script itself around line 75. I didn't make sure we can use that arch for opencv with iOS SDK 4.x though.
    • EXcell said at 09/13, 2010
      After building sample project for 3G with iOS 4.1 running cannot load picture taking with Camera, the process freezes. Any ideas?
    • ice said at 09/13, 2010
      I'm experiencing the same problems when trying to link to your precompiled libraries. I don't get an error message saying that <opencv/cv.h> couldn't be found since I have added the 4 entires under 'build configuration'. But now I get 55 error when compiling, all like



      "_cvPow", referenced from:



      etc.



      What's wrong?

      Thanks for your great work!





    • ice said at 09/14, 2010
      forget about my last comment, I found a work-around

      Thanks for your work!
    • ice said at 09/14, 2010
      well, I have to correct myself. What I thought was a work-around does not work. Thus, I'm trying again to work with your precompiled libraries, but I still get 55 build errors when linking a new project to your library.

      All errors are like:

      "_cvPow", referenced from:

      etc.

    • pkhabio said at 09/15, 2010
      I get same error. 
      What's wrong? ..
    • AM said at 09/15, 2010
      Hi Yoshimasa-

      Thanks so much for your work and support on this project.

      I'm running into a build issue and I wonder if you can help. Everything is fine until I'm at the building static Device library phase (../opencv_cmake.sh Device ../OpenCV-2.1.0
      ) and I get the error

      'iOS SDK Version 4.0 is not found, please select iOS version you have'

      -- I'm running XCode 3.2.4 with iOS 4.1 on Mac 10.6.4 -- (OpenCV 2.1.0 obviously).

      Am I doing something wrong? 

      Thanks again for your help.

    • TK said at 09/16, 2010
      Hi Yoshimasa,

      I just get the same error like "AM" and do not know how to fix this.

      Can you help?
    • TK said at 09/16, 2010
      Hi Yoshimasa,

      Hopefully I did not did anything wrong, but I have fixed the error above by changing line 23 in "opencv_cmake.sh" to:

      if [ -z "$4" ]; then
      SDK_VERSION="4.1"

      I suppose, that the error occures due to the fact that V4.1 of the iOS is new.

      Has this been the fix for that bug?

      Currenty I'm compiling, and everthing seems to work just fine.
    • Hoyoung said at 09/21, 2010
      Hi Yoshimasa-
      I'm thankful your sample code
      very very thank you.

      I'm joining iOS Developer Program, Not yet.

      Excuse...
      Take Photo Camera in Sample Code is Real-time Processing or Take photo -> Face Detect..
      I want to know
    • NC said at 09/26, 2010
      Is there anything I have to do to the project to get it to build?
      I get 48 errors the first of which is Classes/OpenCVTestViewController.m:3:22: error: opencv/cv.h: No such file or directory

      My apologies if Im missing some instructions. All I did was download the project open it in xcode and press run. I am on snow leopard with xcode 3.2.4 and sdk 4.1
    • Yoshimasa Niwa said at 09/26, 2010
      EXcell: Hmm, seems to need to add some changes for iOS 4.1. I'm not have no iPhone 3G device with iOS 4.1 so slightly difficult to make sure it works or not.
      ice, pkhabio: I guess you need to add missing libxxx to your project, same as libcv etc.
      AM, TK: I didn't test iOS SDK 4.1 yet, Apple udpated it frequently so I can't test them all sooner... I'll work with next version, then I'll skip 4.1 so far.
      Hoyung: I'm not completely understanding what you wanted though, if you wanted to implement realtime face detection from video capture, you need to work a lot. This sample is only for still images so far.
      NC: Make sure header and library search paths in the info panel for the build target.
    • NC said at 09/27, 2010
      I used git clone instead of downloading with browser and it started working
      Thanks for your help
    • EXcell said at 09/27, 2010
      Yoshimasa Niwa: Actually I've realized that I cannot make any pictures with Camera.app on 3G after upgrade to 4.1. So the problem might be not related to the OpenCV specifically. Hmm..
    • johndoe said at 09/30, 2010
      hello Yoshimasa-san, why is there no libhighgui library compiled? did your OpenCV-2.1.0. patch has something to do with it?
    • johndoe said at 10/01, 2010
      has anyone tried compiling the nhocr?
    • Carlos Scheidegger said at 10/04, 2010
      Hey guys, I could get OpenCV to at least cross-compile for the device with the iOS 4.1 SDK by manually adding "--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.1.sdk" to opencv_make.sh:74. I'm sure this is a hack and that there are better ways to do it, but at least it's compiling now :)
    • Carlos Scheidegger said at 10/04, 2010
      Just to confirm that the above work - I just ran Yoshimasa's OpenCV demo on my 4G ipod touch using SDK 4.1. Thank you, Yoshimaza, for the great resource!
    • johndoe said at 10/12, 2010
      what is -add_subdirectory(highgui) in OpenCV-2.1.0patch does?
    • りず said at 10/13, 2010
      使わせていただいてますm(_ _)m。

      OpenCV-2.1.0、iOS 4.1の環境で
      cvGetPerspectiveTransformやcvWarpPerspectiveを呼ぶと

      Undefined symbols:
      "_dgesdd_", referenced from:
      cv::SVD::operator()(cv::Mat const&, int)in libcxcore.a(cxlapack.o)
      cv::SVD::operator()(cv::Mat const&, int)in libcxcore.a(cxlapack.o)
      "_sgelsd_", referenced from:
      cv::solve(cv::Mat const&, cv::Mat const&, cv::Mat&, int)in libcxcore.a(cxlapack.o)
      ...

      とエラーになってしまいます。どのように修正したら良いかお分かりでしたらご教示ください。
    • johndoe said at 10/13, 2010
      I'm assuming you had a problem compiling the highgui.. so many dependencies..
    • johndoe said at 10/13, 2010
      Error from debugger: mi_cmd_stack_list_frames: Not enough frames in stack
    • Tina said at 10/13, 2010
      I was getting the same message as りず and ice and pkhabio.
      I followed Jared's instruction (step 6) to set up the library search paths. I don't know what else I'm missing to link libcxcore.a and libcv.a to the project since the libraries are already in the project folder...

      Can anyone help me out?
    • kmiyachi1024 said at 10/13, 2010
      OpenCVを使って書いたアプリをiPhoneで動作させようと思い参考にさせて頂きました。

      OpenCV-2.1.0 , iOS 4.1 用patchを修正しソースよりビルドしてみましたが下記エラーが発生しています。

      "flann::Index::~Index()", referenced from:
      cv::flann::Index::~Index()in libcxcore.a(cxflann.o)
      ld: symbol(s) not found

      対応策等お分かりでしたら、ご教授頂けると助かります。
      また、iPhone上で動作しない関数等あるのでしょうか?
      *ライブラリは全て(libcv,libcvaux,libcxcore,libml)配置してます。

      I tested OpenCV-2.1.0 & iOS4.1 with my project.
      I got the following error..

      "flann::Index::~Index()", referenced from:
      cv::flann::Index::~Index()in libcxcore.a(cxflann.o)
      ld: symbol(s) not found

      if you know how to fix it , please let me know.
      Thanks.

      よろしくお願いします。
    • Mark said at 10/17, 2010
      Hey, great work. Love the code samples & all of the hard work you've done.

      To fix the "Undefined symbols" errors that Tina, りず, ice and pkhabio have had, I added to the "Other Linker Flags" project build setting:

      -lm -lz -lstdc++

      This left a few errors still:

      Undefined symbols:
      "_dgesdd_", referenced from:

      etc. 

      A bit of googling showed this to be the 'lapack' libraries, which are included in the Accelerate framework in iOS4. To continue you need to add that framework to your project.
    • r618 said at 10/18, 2010
      dude, you got the digg it link wrong
      I digget it anyway with proper URL
      take care & thanks
    • Yoshimasa Niwa said at 10/19, 2010
      r618: I've update digg link to digg button :)
      johndoe: highgui doesn't work on iOS, I think, and nhocr looks interesting :)
      kmiyachi1024: give -lstdc++ may solve the issue, hopefully, I didn't make sure though.
      all: I guess current build script may not work with iOS SDK 4.1. I change my mind then I'll update it for SDK 4.1 and 4.2 (if it's in public, because of NDA.)
    • johndoe said at 10/19, 2010
      I needed the cvLoadImage in HighGUI. Thanks anyway. Guys, dont forget the linker if you want it working in the device. -lstdc++ also set the accelerate framework to weak
    • johndoe said at 10/20, 2010
      My friend could you cross compile the nhocr :-) its for japanese :-)
    • johndoe said at 10/20, 2010
      #!/bin/sh
      # build_fat.sh
      # nhocr

      outdir=outdir
      mkdir -p $outdir/arm $outdir/i386

      make clean
      make distclean
      unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD

      export DEVROOT=/Developer/Platforms/iPhoneOS.platform/Developer
      export SDKROOT=$DEVROOT/SDKs/iPhoneOS4.0.sdk
      export CFLAGS="-arch armv6 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/ -I/Users/johndoe/Desktop/O2-tools-2/include/ -I/Users/johndoe/Desktop/O2-tools-2/lib/"
      export CPPFLAGS="$CFLAGS"
      export CXXFLAGS="$CFLAGS"
      export LDFLAGS="-L$SDKROOT/usr/lib/"
      export LD="$DEVROOT/usr/bin/ld"
      export CPP="$DEVROOT/usr/bin/cpp-4.2"
      export CXX="$DEVROOT/usr/bin/g++-4.2"
      export CC="$DEVROOT/usr/bin/gcc-4.2"

      ./configure --host=arm-apple-darwin \
      --with-O2tools=/Users/johndoe/Desktop/O2-tools-2/lib/

      make -j3

      cp libnhocr/libnhocr.a $outdir/arm/libnhocr_armv6.a

      make distclean
      unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT LD

      export DEVROOT=/Developer/Platforms/iPhoneSimulator.platform/Developer
      export SDKROOT=$DEVROOT/SDKs/iPhoneSimulator4.0.sdk
      export CFLAGS="-arch i386 -pipe -no-cpp-precomp -isysroot$SDKROOT -miphoneos-version-min=3.0 -I$SDKROOT/usr/include/ -I/Users/johndoe/Desktop/O2-tools-2/include/"
      export CPPFLAGS="$CFLAGS"
      export CXXFLAGS="$CFLAGS"
      export LDFLAGS="-L$SDKROOT/usr/lib/"
      export LD="$DEVROOT/usr/bin/ld"
      export CPP="$DEVROOT/usr/bin/cpp-4.2"
      export CXX="$DEVROOT/usr/bin/g++-4.2"
      export CC="$DEVROOT/usr/bin/gcc-4.2"

      ./configure --with-O2tools=/Users/johndoe/Desktop/O2-tools-2/outdir/

      make -j3

      cp libnhocr/libnhocr.a $outdir/i386/libnhocr_i386.a

      /usr/bin/lipo -arch armv6 $outdir/arm/libnhocr_armv6.a -arch i386 $outdir/i386/libnhocr_i386.a -create -output $outdir/libnhocr.a

      unset CPPFLAGS CFLAGS LDFLAGS CPP CXX CC CXXFLAGS DEVROOT SDKROOT



    • johndoe said at 10/20, 2010
      this has errors..
    • Fumi22 said at 10/20, 2010
      I have a problem when I try to use: cvCreateGaussianBGModel

      The compiler say that symbol not exists.. 
      Your demo works perfect
    • りず said at 10/21, 2010
      Hi, Mark.

      Thanks to you, I compiled it successfully.
    • Lokey said at 10/21, 2010
      When try use functions of opencv/cvaux.h I have a problem:

      CvGaussBGStatModelParams *params;
      params->win_size=2;

      in second line I have EXEC_BAD_ACCESS..
    • kmiyachi1024 said at 10/22, 2010
      hello Yoshimasa-san,Thanks for your reply.
      I set -lm -lz -lstdc++ options, and it working fine.

      thanks a lot.
    • Tina said at 10/23, 2010
      Thanks to Mark, after upgrading the sdk for iOS4, I finally got it compiled successfully.
    • vcnepo said at 10/23, 2010
      I've tried to set this up in a fresh project and reading the earlier posts about editing project settings, and still get many errors. Can anyone list the exact directions for set up please?
    • Cameron Griffin said at 10/24, 2010
      Hi, i would like to know if cvCalcOpticalFlowFarneback is available in the iphone version of open cv. I cant seem to find it.

      Cheers
    • Scott said at 10/27, 2010
      Thanks for the great work... I'm having the same problem as Ashish Lal:

      error: -mmacosx-version-min not allowed with -miphoneos-version-min

      make[1]: *** [CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o] Error 1

      make: *** [cmTryCompileExec/fast] Error 2

      This is with cmake-2.8 from MacPorts, iOS4.1 and 10.6.4.

      Anybody successfully compile with cmake 2.8? It seems it's always adding the -mmin-macosx-version flag
    • Craig said at 10/27, 2010
      I am also having compile problems for the "Device".
      ld: warning: in /Developer/SDKs/MacOSX10.6.sdk/usr/lib/crt1.o, missing
      required architecture armv6 in file

      Furthermore, I tried creating my own XCode project and make use of the libs from this project. The project compiles with iPhone (Release and Debug), and Simulator (Release). But fails with Simulator-Debug. Build results in 59 errors because of missing references (_gzclose, _dgesdd_ etc.)

      I am using iOS 4.0 and SDK 3.2 on 10.6.4
    • msdark said at 10/29, 2010
      (First... Sorry for my english... but i speak spanish xD)

      Great Job!!!... i working with your code trying something to a project that i have...

      In the simulator run flawessly .. but in my ipod touch (2G) is a real pain...

      Well...i trying something to make it more "efficient" (in time consume)... the float algorithms don't run good in arm processor for this i searching for solution.. and Android help me... here ( http://pastebin.com/4VXABM6g )is a Integer algorithm for cvHaarDetectObjects ...

      To use this just modify cv.h (include/opencv/cv.h in Opencv-2.1.0 folder) to add the new functions:

      CVAPI(CvSeq*) mycvHaarDetectObjects( const CvArr* image,
      CvHaarClassifierCascade* cascade,
      CvMemStorage* storage, double scale_factor CV_DEFAULT(1.1),
      int min_neighbors CV_DEFAULT(3), int flags CV_DEFAULT(0),
      CvSize min_size CV_DEFAULT(cvSize(0,0)));

      CVAPI(void) mycvSetImagesForHaarClassifierCascade( CvHaarClassifierCascade* cascade,
      const CvArr* sum, const CvArr* sqsum,
      const CvArr* tilted_sum, double scale );

      CVAPI(int) mycvRunHaarClassifierCascade( CvHaarClassifierCascade* cascade,
      CvPoint pt, int start_stage CV_DEFAULT(0));


      this improve a little the performance of opencv's face detector.

      The other idea i take from Android world is emulate a camera in the simulator to make tests.

      how? using Sockets.. you can use a java application to take frames from a webcam and then pass this frames through socket... in the iPhone simulator you can connect to this service and grab the frames, detect the face and show them... works really nice with Android Emulator.. but i can't do this with iPhone Simulator ... i recently learn Objective-C and i lookin how i can do the same..

      Happy coding!!
    • msdark said at 10/29, 2010
      Hey!!!.. i was forgotten..

      Here is some guy's code that aims to have "near real time face detection" with iPhone http://code.google.com/p/morethantechnical/source/browse/#svn/trunk/FaceDetector-iPhone

      http://www.morethantechnical.com/2009/08/09/near-realtime-face-detection-on-the-iphone-w-opencv-port-wcodevideo/

      this is the same what we can do with your work???

      Thanks in advace
    • Yoshimasa Niwa said at 10/31, 2010
      johndoe: Thanks for your comments!
      Fumi22: You may need to add libcvaux.a which you can build from OpenCV source by using my build script. It is not included in my demo application repository.
      りず, Mark, kmiyachi1024, Tina: Thank you for your comments, I've updated this article texts.
      Lokey: Hmmm... bug?
      vcnepo: I've updated this article, should be helpful :)
      Cameron Griffin: You probably can use that. It seems to be in libcv.a, which is included in this demo application repository.
      Scott: I'm using cmake 2.8.1 and cmake 2.8.2 which you can install from MacPorts.
      Craig: please try to add "-lstdc++" to other linker flags settings in your project. last updates on this article may help you.
      msdark: I didn't try to grab image frames from iPhone camera yet, but it should be doable with iOS SDK 4.x. I'm going to try that when I have a time.
    • johndoe said at 10/31, 2010
      Opencv 2.2 is due to be released this month. I hope Niwa-san can cross compile it again. :-) Moshi jikan ga attara, cross-compile shitekudasai. :-)
    • Jakub said at 11/03, 2010
      Great work. Thanks a lot for this!
      I have one small question:
      - in the CreateIplImageFromUIImage method you create two instances of IplImage and you return the second instance. Why do you need both instances? Isn't the first one enough?
    • Yoshimasa Niwa said at 11/08, 2010
      Jakub: because we need BGR color order.
    • Ignacio said at 11/14, 2010
      Yoshimasa-san 
      Thanks again for this example! I have come back after a while since I want to use OpenCV and iPhone again and found a very silly but common problem and thought below note could help others.

      (This happens not only in this opencv project but other UNIX, etc projects hence this is not specific to this iPhone+Opencv post but anyway...)

      Well it turns out that if $(SRCROOT) Xcode variable contains spaces, then compiling the project will give you: '#import <opencv/cv.h> 
      error: opencv/cv.h: no such file or directory'. 

      For newbs: make sure your xcode project path has no spaces in it. Otherwise you might loose some time before you realize that the problem is that SRCROOT is not well read/parsed and not your settings 

    • msdark said at 11/17, 2010
      Well, finally I managed to use the OpenCV face detector for a video .. at first i thought in using the same approach used for the Android emulator. Capture Frames from a socket with a WebCamBroadcaster server, but this did not work, so I investigated I found this:www.codza.com/extracting-frames-from-movies-on-iphone . The idea is to use ffmpeg to get frames from a video. These frames are UIImages so it was easier to use the detector.

      In the emulator works quite well (obviously), then tried it on my iPod Touch 2G, its performance is abysmal. 0 fps when trying to recognize faces, even using the detection algorithm modified to only use Integers.

      Any ideas on how to improve the detection performance?

      Greetings
    • Mohammad Asif said at 12/01, 2010
      Hi, 

      Thanks for pre-compiled OpenCV for iPhone its really help full 

      Thanks,
    • Stéphane Péchard said at 12/06, 2010
      Hi,
      I just managed to use the last version of this script with OpenCV 2.2 and SDK 4.2. You just need to remove dependancies to highgui into cmake files.

      Thanks for this!
    • Yoshimasa Niwa said at 12/06, 2010
      Stéphane: I'll update the code soon, thanks!
    • Cres said at 12/12, 2010
      Stephane, is there anyway you can provide the compiled libs? I have been trying to get this to compile and have had no luck yet. I will continue to try in the meantime.

      Thanks in Adavnce
    • Vladimir said at 12/15, 2010
      For those that are getting compile time errors about files not found, try adding "-isysroot ${SDK_ROOT}" to FLAGS in opencv_cmake.sh

      In addition, I thought I could make OpenCV faster by including extra compiler flags, but OpenCV 2.1 on IOS4.1 was not any faster with these flags:

      -mfpu=neon -funsafe-math-optimizations -mfloat-abi=softfp -ffast-math -O3

      With out the "-O3" my app was slower by 40%. My app does skin and face detection.
    • Yasuhiro Yoshimura said at 12/30, 2010
      Hi, 
      I described the method to use OpenCV 2.2 on iOS SDK 4.1.
      http://bit.ly/i1n8a7

      Thanks in advance!
    • Borluse said at 01/06, 2011
      To Yasuhiro Yoshimura:
      Sorry for my poor english. 

      I followed your instructions. But when i include <opencv2/opencv.hpp> and tried to compile, il saids opencv2/calib3d/calib3d.hpp not found. So i just removed it, and added the <opencv2/features2d/features2d.hpp>. (i want to use SURF) But this time, i got another error: "statement-expressions are allowed only inside functions". Do you know how to fix it? 

      Thanks in advance!
    • Yasuhiro Yoshimura said at 01/07, 2011
      Hi, Borluse.

      In the my way, "calib3d" module is removed from
      build target.Because,I think that this module is used less frequently on iOS.

      Therefore, the following error occurs.
      "opencv2/calib3d/calib3d.hpp not found"

      For the 2nd error,could you add "-lstdc++" as linker flag to your project? This linker flag is used to expressly link C++ library.

      Thanks in advance!
    • Yasuhiro Yoshimura said at 01/08, 2011
      Hi, Borluse.
      Sorry, I was wrong about the solution described above.
      Perhaps this page's information might be helpful for you.
      http://computer-vision-talks.com/2010/12/building-opencv-for-ios/
    • Saitoh Koki said at 01/09, 2011
      サンプルコードを拝見しました。

      OpenCVTest.xcodeprojについて、質問があります。

      "OpneCVTest"の情報から、ヘッダ検索パスの項目を見ても、何も設定されていないようですが、opencv/cv.hはインクルードできています。
      インクルードパスの設定は、どこで設定されているのですか?
    • Yasuhiro Yoshimura said at 01/10, 2011
      Saitoh Kokiさん
      Xcodeで[ターゲット]-[OpneCVTest]を確認して頂くと「ヘッダ検索パス」が指定されていると思います.
    • Saitoh Koki said at 01/10, 2011
      Yasuhiro Yoshimuraさん
      返信ありがとうございます。

      Xcodeで[ターゲット]-[OpneCVTest]を確認して頂くと「ヘッダ検索パス」に、指定されているのを確認しました。

      もうひとう質問させてください。
      「ヘッダ検索パス」には、「Any iOS」と「Any iOS Simulator」の二つの項目があります。
      新規でこの二つの項目を設定する方法をご教授いただけますでしょうか?
    • Parag said at 01/11, 2011
      Thank you it works beautifully! Hoping to see this incorporated into the OpenCV library soon.
    • Borluse said at 01/13, 2011
      Thanks all.

      Finally, i have been able to solve the problem "statement-expressions are allowed only inside functions". I put a #include "core.hpp" in the prefix header file prefix.pch just before #import <UIKit/UIKit.h> in the block #ifdef __OJBC__. 

      This problem due to a defined macro MIN in the file core.hpp. To solve this, we must put the include before any include/import.

      Thanks again to Yasuhiro Yoshimura.

      Hope this helps.
    • simon said at 01/17, 2011
      hey Yoshimasa,
      what a great page!! it's probably the first iPhone project (with such advanced libs) i could download and it worked perfectly from the beginning. perfect!!
      i have some questions regarding opencv on the iPhone and in general, maybe you can help me:
      1. you have a "how-to" for opencv 2.2 and iOS 4.* but do u have also a download link for the compiled libraries like you had on the earlier version? would be fantastic
      2. i'm really new to openCV anyway but i'm not really sure which technology i need for my problem: i want the iPhone to recognize objects (if possible on the live stream) like credit-cards. it should recognize the card as a card, and show overlays for different parts of the card (let's say: card-no, date of expiry, name). and now i don't know what technique i should use since cv is a big cloud of questionmarks for me. i tried pattern matching, which was not very successfull then i came to the example find_object.cpp which is included in the opencv 2.2 samples and uses surf (this was much better).

      can anyone out there tell me in which direction i should look for a solution? :)

      thank's a lot

      simon
    • Borluse said at 01/18, 2011
      Hi simon,

      This is what i am doing now.

      You can try SURF and SIFT. The 2 algo can extract the keypoints from an image. You can then calculate a distance between them and the keypoints extract from another image. 

      More the distance is short, more similar they are.

      Hope you can understand. LOL. My english is really poor...
    • Tyua said at 01/19, 2011
      first of all, thank you very much for your blog & efforts to help about using opencv on iphone

      i have succeeded to run the camera calibration algorithms on my iphone by using your openCV_2.1 version, and have also compiled openCV_2.2, but linker tells me it fails to find methods related to calib3d.hpp: "cvCalibrateCamera2", "cvFindChessboardCorners" and "cvDrawChessboardCorners"
      i have added to my project frameworks all openCV 2.2 libs generated, but no libopencv_calib3d.a, the module is declared in OpenCV-2.2.0, but not generated

      did i miss something ?
    • Tyua said at 01/19, 2011

      i solved my problem : in :
      iphone_opencv_test/OpenCV-2.2.0/modules/CMakeLists.txt

      add_subdirectory(calib3d) was commented
    • Junior said at 01/20, 2011
      Hi Tyua, can you tell me how you compiled it? I'm new to this whole terminal thing, and when I use what's supplied in this blog, i get no such directory (when patching or anything else). 

      Yes, I am a complete newbie =/, thanks in advance.
    • Tyua said at 01/24, 2011
      Junior : compile opencv 2.1.0 then patch from http://bit.ly/i1n8a7 after having replaced opencv 2.1.0 by opencv 2.2.0
    • Shamir said at 01/25, 2011
      Hi yoshimasa, I've been trying to compile OpenCV on my Mac instead of my iPhone. I was wondering if the same instructions you supply here apply to the Mac also. If not, do you know of a website which can explain to me how to compile OpenCV on the Mac inside Xcode? Thanks :)
    • Haqn said at 01/31, 2011
      Thanx Ignacio for your warning!!! That was really helpful, damn i tried it 3 times!.. Btw thanx so much for the tutorial Niwa..
    • amit said at 02/06, 2011
      Hi Yoshimasa, 



      great blog, i am having a great time using the project. 

      I am trying to use the grabCut function as in the sample project. The function returns very quickly and actually does nothing. 

      I haven't got a clue whats the problem. is there a way to debug the opencv code (i have downloaded and built the source using youre instruction above)



      Thanks in advance, 

      Amit
    • Radek said at 02/24, 2011
      Hi, i had an error like:
      OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /Volumes/ramdisk/iphone_opencv_test/OpenCV-2.1.0.patched/src/cxcore/cxpersistence.cpp, line 4720
      terminate called after throwing an instance of 'cv::Exception'
      what(): /Volumes/ramdisk/iphone_opencv_test/OpenCV-2.1.0.patched/src/cxcore/cxpersistence.cpp:4720: error: (-2) The node does not represent a user object (unknown type?) in function cvRead

      and putting :
      CvHaarClassifierCascade * cascade = 0;
      cvReleaseHaarClassifierCascade(&cascade);

      before line:
      cascade = (CvHaarClassifierCascade*)cvLoad([path cStringUsingEncoding:NSASCIIStringEncoding], NULL, NULL, NULL);

      hope that helps someone...

      and thanks for a project!
    • Xiaoyi said at 03/03, 2011
      Hi Yoshimasa, thanks for your post! We are trying to migrate an open source project based on OpenCV to iPhone but it uses imread function which depends on highgui library. Following the steps in this post does not give us a satisfactory result. Do you know how to modify the script to build the highgui static lib, or at least the part with imread? We figured imread function probably should be working on iphone since it mainly deal with file operations. Thanks for any help!
    • Leonard said at 03/07, 2011
      Hi Yoshimasa, excellent resource, thank you :)

      I am following another guide to build OpenCV 2.2 on iOS 4.2 found here: http://www.atinfinity.info/wiki/index.php?OpenCV/Using%20OpenCV%202.2%20on%20iOS%20SDK%204.2 (sorry about the mammoth link! Didn't want to use bit.ly or whatever in case it was seen as spam).

      When I try to compile on MacOSX 10.6 using cmake I am getting these errors:


      ld: warning: in
      /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/libSystem.dylib,
      file was built for i386 which is not the architecture being linked (x86_64)

      Undefined symbols:

      "_exit", referenced from:
      start in crt1.10.6.o

      ld: symbol(s) not found

      collect2: ld returned 1 exit status

      make[1]: *** [cmTryCompileExec] Error 1

      make: *** [cmTryCompileExec/fast] Error 2

      CMake will not be able to correctly generate this project.
      Call Stack (most recent call first):
      CMakeLists.txt:47 (project)

      -- Configuring incomplete, errors occurred!

      The problem here seems to be that OSX is trying to compile for x86_64 - I think there is a bug in 10.6 where having i386 in your CMAKE_OSX_ARCHITECTURES flag makes it think it's the default, but then tells the compiler to go back to default (which on 10.6 is x86_64)!

      Has anyone encountered this problem, and/or knows how to fix it? Thanks
    • Yasuhiro Yoshimura said at 03/09, 2011
      Hi, Leonard
    • Yasuhiro Yoshimura said at 03/09, 2011
      Hi, Leonard

      The CMAKE_OSX_ARCHITECTURE is 'ARCH="i386"' in opencv_cmake.sh.
      If you possible, could you try to change to 
      'ARCH="x86_64"'?

      Thanks in advance,

      Yasuhiro Yoshimura
    • KG said at 03/10, 2011
      いつも参考にさせていただいています。Xcode4にアップデートすると、デバイスで実行できなくなりました。これはcmakeの中身を変更してビルドし直さなければいけないのでしょうか?
    • Leonard said at 03/11, 2011
      Hi Yasuhiro, I actually tried that already - I still get the same error (sorry about the length of the post in advance):

      admins-MacBook:build_simulator leonard$ ../opencv_cmake.sh Simulator http://www.cnblogs.com/OpenCV-2.2.0/
      Starting cmake...
      Target SDK = iPhoneSimulator
      iOS SDK Version = 4.2
      iOS Deployment Target = 4.2
      OpenCV Root = http://www.cnblogs.com/OpenCV-2.2.0/
      OpenCV Install Prefix = /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_simulator/../opencv_simulator

      -- The C compiler identification is GNU
      -- The CXX compiler identification is GNU
      -- Checking whether C compiler has -isysroot
      -- Checking whether C compiler has -isysroot - yes
      -- Checking whether C compiler supports OSX deployment target flag
      -- Checking whether C compiler supports OSX deployment target flag - yes
      -- Check for working C compiler: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc
      -- Check for working C compiler: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -- broken
      CMake Error at /Applications/CMake 2.8-4.app/Contents/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
      The C compiler
      "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" is
      not able to compile a simple test program.

      It fails with the following output:

      Change Dir: /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_simulator/CMakeFiles/CMakeTmp



      Run Build Command:/usr/bin/make "cmTryCompileExec/fast"

      /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make
      CMakeFiles/cmTryCompileExec.dir/build

      "/Applications/CMake 2.8-4.app/Contents/bin/cmake" -E cmake_progress_report
      /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_simulator/CMakeFiles/CMakeTmp/CMakeFiles
      1

      Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o

      /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc
      -isysroot
      /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk
      -mmacosx-version-min="10.6" -o
      CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c
      /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_simulator/CMakeFiles/CMakeTmp/testCCompiler.c


      Linking C executable cmTryCompileExec

      "/Applications/CMake 2.8-4.app/Contents/bin/cmake" -E cmake_link_script
      CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1

      /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc
      -isysroot
      /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk
      -mmacosx-version-min="10.6" -Wl,-search_paths_first
      -Wl,-headerpad_max_install_names
      CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -o cmTryCompileExec

      ld: warning: in
      /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/lib/libSystem.dylib,
      file was built for i386 which is not the architecture being linked (x86_64)

      Undefined symbols:

      "_exit", referenced from:
      start in crt1.10.6.o

      ld: symbol(s) not found

      collect2: ld returned 1 exit status

      make[1]: *** [cmTryCompileExec] Error 1

      make: *** [cmTryCompileExec/fast] Error 2





      CMake will not be able to correctly generate this project.
      Call Stack (most recent call first):
      CMakeLists.txt:47 (project)


      -- Configuring incomplete, errors occurred!


      Interestingly, I also get an error when compiling for the device too:


      admins-MacBook:build_simulator leonard$ ../opencv_cmake.sh Device http://www.cnblogs.com/OpenCV-2.2.0/
      Starting cmake...
      Target SDK = iPhoneOS
      iOS SDK Version = 4.2
      iOS Deployment Target = 4.2
      OpenCV Root = http://www.cnblogs.com/OpenCV-2.2.0/
      OpenCV Install Prefix = /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_simulator/../opencv_device

      -- The C compiler identification is GNU
      -- The CXX compiler identification is GNU
      -- Checking whether C compiler has -isysroot
      -- Checking whether C compiler has -isysroot - yes
      -- Checking whether C compiler supports OSX deployment target flag
      -- Checking whether C compiler supports OSX deployment target flag - yes
      -- Check for working C compiler: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
      -- Check for working C compiler: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -- broken
      CMake Error at /Applications/CMake 2.8-4.app/Contents/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
      The C compiler
      "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" is not able
      to compile a simple test program.

      It fails with the following output:

      Change Dir: /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_simulator/CMakeFiles/CMakeTmp



      Run Build Command:/usr/bin/make "cmTryCompileExec/fast"

      /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make
      CMakeFiles/cmTryCompileExec.dir/build

      "/Applications/CMake 2.8-4.app/Contents/bin/cmake" -E cmake_progress_report
      /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_simulator/CMakeFiles/CMakeTmp/CMakeFiles
      1

      Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o

      /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -isysroot
      /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
      -mmacosx-version-min="10.6" -o
      CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c
      /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_simulator/CMakeFiles/CMakeTmp/testCCompiler.c


      Linking C executable cmTryCompileExec

      "/Applications/CMake 2.8-4.app/Contents/bin/cmake" -E cmake_link_script
      CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1

      /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -isysroot
      /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk
      -mmacosx-version-min="10.6" -Wl,-search_paths_first
      -Wl,-headerpad_max_install_names -miphoneos-version-min=4.2
      CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -o cmTryCompileExec

      ld: library not found for -lcrt1.10.6.o

      collect2: ld returned 1 exit status

      make[1]: *** [cmTryCompileExec] Error 1

      make: *** [cmTryCompileExec/fast] Error 2





      CMake will not be able to correctly generate this project.
      Call Stack (most recent call first):
      CMakeLists.txt:47 (project)


      -- Configuring incomplete, errors occurred!


      Starting to go a bit over my head now... any ideas anyone?
    • Sergei L. said at 03/11, 2011
      Hi Yoshimasa,



      Thanks a lot for the resource! It helped me a lot!

      However to compile OpenCV for iPhone on my Mac two changes were needed in opencv_cmake.sh file:

      1) FLAGS="-miphoneos-version-min=${IPHONEOS_VERSION_MIN}" => FLAGS="-arch armv6 -miphoneos-version-min=${IPHONEOS_VERSION_MIN}"



      2) FLAGS="" => FLAGS="-arch i386"



      Best regards,

      Sergei L.
    • Yasuhiro Yoshimura said at 03/12, 2011
      Hi, Leonard

      Previously, a similar error occur in my environment. If you possiple, please try 2 solution.

      (1)
      Plase install CMake from MacPorts.
      If you have installed official cmake package,
      you need to delete CMake's symbolic link from /usr/bin/.

      (2)
      Please insert "-D CMAKE_SYSTEM_PROCESSOR=arm" to opencv_cmake.sh in TARGET_SDK=device case.

      Best regards,
      Yasuhiro Yoshimura
    • Leonard said at 03/14, 2011
      Hi Yasuhiro,

      I did as you said (removed the link to cmake in /usr/bin then installed cmake with MacPorts) but I still get the following error with Device build:


      CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
      The C compiler
      "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" is not able
      to compile a simple test program.

      It fails with the following output:

      Change Dir: /Users/leonard/Development/Goog/niw-iphone_opencv_test-4ab0572/build_device/CMakeFiles/CMakeTmp


      And with Simulator build:


      -- Check for working C compiler: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -- broken
      CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
      The C compiler
      "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" is
      not able to compile a simple test program.

      (This is not using the gcc-4.0 anymore, just the standard one)

      Thanks
    • Celso said at 03/14, 2011
      Hi Yasuhiro,

      I'm having the exact same problem Leonard had.

      My iOS version is 4.2 (needed to change on cmake script).

      Any insight ?
      Best Regards
    • Marc Fernandez said at 03/14, 2011
      Hi Celso and Leonard, I had the same issue and now it seems that it works. What I did:
      Uninstall the cmake installed with MacPorts
      >> sudo port uninstall cmake -gui

      It seems that it's a bug in that last 2.8.2 version of cmake. So then go to http://www.cmake.org/cmake/resources/software.html and install the previous 2.6.4 version.

      That worked for me.

      Cheers,
      Marc
    • Marc Fernandez said at 03/14, 2011
      I got another error now in the 
      >>make -j 4
    • noob said at 03/14, 2011
      i just pulled the latest sample from git - loaded it up in xcode4 and tried to build/deploy to the device and received this:


      'setAllowsImageEditing:' is deprecated (declared at /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIImagePickerController.h:110)
      file://localhost/Users/mabbott/projects/iphone_opencv_test/Classes/OpenCVTestViewController.m: warning: Deprecations: 'allowsImageEditing' is deprecated

      ld: warning: ignoring file /Users/mabbott/projects/iphone_opencv_test/opencv_device/lib/libcv.a, file was built for archive which is not the architecture being linked (armv7)

      ld: warning: ignoring file /Users/mabbott/projects/iphone_opencv_test/opencv_device/lib/libcxcore.a, file was built for archive which is not the architecture being linked (armv7)

      "_cvSetErrMode", referenced from:

      "_cvCreateMemStorage", referenced from:

      "_cvReleaseHaarClassifierCascade", referenced from:

      "_cvCanny", referenced from:

      "_cvCvtColor", referenced from:

      "_cvReleaseMemStorage", referenced from:

      "_cvGetSeqElem", referenced from:

      "_cvCreateImage", referenced from:

      "_cvLoad", referenced from:

      "_cvReleaseImage", referenced from:

      "_cvGetSize", referenced from:

      "_cvPyrDown", referenced from:

      "_cvHaarDetectObjects", referenced from:

      thoughts?
      thanks!
    • Leonard said at 03/15, 2011
      Hernandez: Do you know if the bug is still apparent in 2.8.4? That's what I had installed, not 2.8.2. I'm going to leave cmake from MacPorts on for now in case there's another way of fixing this, because it seems that it's the gcc compiler part that's failing.

      For now I'm using the pre-compiled project, which works first time on both Simulator and Device builds. I still need to read up and figure out how to make things like cvExtractSURF to work though :/
    • Yasuhiro Yoshimura said at 03/15, 2011
      Hi, Leonard

      I made OpenCV framework for iOS.
      http://bit.ly/i2Woem

      If this problem is difficult to resolve,
      please use this framework.

      Best regards,
      Yasuhiro Yoshimura
    • Haqn said at 03/15, 2011
      Anyone could build for iOS 4.3? I havent tried yet but I want to if it possible :) i think it depends on script so Yoshimura may edit it maybe soon?
    • Leonard said at 03/16, 2011
      @Yasuhiro: I'll try that one thanks, though I'm not entirely sure how to add the framework, but I appreciate it, thanks a lot :) I ended up downloading pre-compiled static libraries for the latest(ish) build here: http://computer-vision-talks.com/2011/02/building-opencv-for-iphone-in-one-click/ and using this guide to make it work in Xcode: http://computer-vision-talks.com/2011/01/using-opencv-in-objective-c-code/

      Haqn: See above. The download for pre-compiled libraries I used works in Xcode 4 with iOS 4.3 (tried on build and simulator)
    • Haqn said at 03/16, 2011
      Hmm I'll try pre-compiled ones. Thanks Leanord..
    • Haqn said at 03/17, 2011
      @Leonard: Could you work Yasuhiro's project with these libraries from the link?
    • Leonard said at 03/21, 2011
      @Haqn: I didn't try Yasuhiro's project no - but if you're having problems maybe it's paths? iirc you can't use namespaces in Obj-C - I'm using cv::Mat, for instance.

      I'm trying to take the simple_matching.cpp from the sample folder and make it work on the iPhone... tough :P
    • Alan Tam said at 03/22, 2011
      I would like to know how to use it in iOS4.3, I have try to compiled use the code seems, that's still not working as well.

      I have tried the link your mentioned to download the OpenCV 2.2.0, and try to run it. I still got the error message.

      Would you please help me to check the problem that what I am missing or what problem happen? I really follow the step until "../opencv_cmake.sh Simulator ../OpenCV-2.2.0
      " that is failed. Thanks a lot!

      Starting cmake...
      Target SDK = iPhoneSimulator
      iOS SDK Version = 4.3
      iOS Deployment Target = 3.0
      OpenCV Root = ../OpenCV-2.2.0
      OpenCV Install Prefix = /Users/tampaklun/iphone_opencv_test/build_simulator/../opencv_simulator

      -- The C compiler identification is GNU
      -- The CXX compiler identification is GNU
      -- Checking whether C compiler has -isysroot
      -- Checking whether C compiler has -isysroot - yes
      -- Checking whether C compiler supports OSX deployment target flag
      -- Checking whether C compiler supports OSX deployment target flag - yes
      -- Check for working C compiler: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc
      -- Check for working C compiler: /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -- broken
      CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:52 (MESSAGE):
      The C compiler
      "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" is
      not able to compile a simple test program.

      It fails with the following output:

      Change Dir: /Users/tampaklun/iphone_opencv_test/build_simulator/CMakeFiles/CMakeTmp



      Run Build Command:/usr/bin/make "cmTryCompileExec/fast"

      /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make
      CMakeFiles/cmTryCompileExec.dir/build

      /opt/local/bin/cmake -E cmake_progress_report
      /Users/tampaklun/iphone_opencv_test/build_simulator/CMakeFiles/CMakeTmp/CMakeFiles
      1

      Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o

      /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc
      -isysroot
      /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk
      -mmacosx-version-min="10.6" -o
      CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c
      /Users/tampaklun/iphone_opencv_test/build_simulator/CMakeFiles/CMakeTmp/testCCompiler.c


      Linking C executable cmTryCompileExec

      /opt/local/bin/cmake -E cmake_link_script
      CMakeFiles/cmTryCompileExec.dir/link.txt --verbose=1

      /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc
      -isysroot
      /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk
      -mmacosx-version-min="10.6" -Wl,-search_paths_first
      -Wl,-headerpad_max_install_names
      CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -o cmTryCompileExec

      ld: warning: in
      /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/libSystem.dylib,
      file was built for i386 which is not the architecture being linked (x86_64)

      Undefined symbols:

      "_exit", referenced from:
      start in crt1.10.6.o

      ld: symbol(s) not found

      collect2: ld returned 1 exit status

      make[1]: *** [cmTryCompileExec] Error 1

      make: *** [cmTryCompileExec/fast] Error 2





      CMake will not be able to correctly generate this project.
      Call Stack (most recent call first):
      CMakeLists.txt:47 (project)


      -- Configuring incomplete, errors occurred!

    • Leonard said at 03/30, 2011
      I've been playing with the demo project, and everything was working lovely until I recently got Xcode 4 final release. The last RC was building just fine on both device and simulator, but with the final Xcode 4 release it will still work on the simulator but on the device I get the following warnings (which ultimately stop it building):

      ld: warning: ignoring file /dev/project/opencv_device/lib/libcv.a, file was built for archive which is not the architecture being linked (armv7)
      ld: warning: ignoring file /dev/projecte/opencv_device/lib/libcxcore.a, file was built for archive which is not the architecture being linked (armv7)

      I presume I will no longer be able to use the libraries with 4.3 then as they were compiled for armv6, and not armv7? Has anyone managed to compile these successfully for 4.3 and/or armv7? I cannot compile unfortunately as my Mac still seems to have problems with cmake, etc, as listed above.

      cheers all
    • Arfius said at 04/01, 2011
      I tried to compile the iphone_opencv_test and I get an error. 
      I have this configuration of system:
      -snow leopard 10.6.7
      -ios 4.3.1 
      -xcode 4

      This is my output running the command 
      ../opencv_cmake.sh Device ../OpenCV-2.1.0


      Starting cmake...
      Target SDK = iPhoneOS
      iOS SDK Version = 4.3
      iOS Deployment Target = 3.1
      OpenCV Root = ../OpenCV-2.1.0
      OpenCV Install Prefix = /Users/alfonso/Documents/XCodeProject/opencv/iphone_opencv_test/build_device/../opencv_device

      -- The C compiler identification is GNU
      -- The CXX compiler identification is GNU
      -- Checking whether C compiler has -isysroot
      -- Checking whether C compiler has -isysroot - yes
      -- Check for working C compiler: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc
      -- Check for working C compiler: /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -- broken
      CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake:50 (MESSAGE):
      The C compiler
      "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" is not able
      to compile a simple test program.

      It fails with the following output:

      Change Dir: /Users/alfonso/Documents/XCodeProject/opencv/iphone_opencv_test/build_device/CMakeFiles/CMakeTmp



      Run Build Command:/usr/bin/make "cmTryCompileExec/fast"

      /usr/bin/make -f CMakeFiles/cmTryCompileExec.dir/build.make
      CMakeFiles/cmTryCompileExec.dir/build

      /opt/local/bin/cmake -E cmake_progress_report
      /Users/alfonso/Documents/XCodeProject/opencv/iphone_opencv_test/build_device/CMakeFiles/CMakeTmp/CMakeFiles
      1

      Building C object CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o

      /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6
      -isysroot
      /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk
      -mmacosx-version-min=10.6 -miphoneos-version-min=3.0 -o
      CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o -c
      /Users/alfonso/Documents/XCodeProject/opencv/iphone_opencv_test/build_device/CMakeFiles/CMakeTmp/testCCompiler.c



      /Users/alfonso/Documents/XCodeProject/opencv/iphone_opencv_test/build_device/CMakeFiles/CMakeTmp/testCCompiler.c:1:
      error: -mmacosx-version-min not allowed with -miphoneos-version-min

      make[1]: *** [CMakeFiles/cmTryCompileExec.dir/testCCompiler.c.o] Error 1

      make: *** [cmTryCompileExec/fast] Error 2





      CMake will not be able to correctly generate this project.
      Call Stack (most recent call first):
      CMakeLists.txt:39 (project)

      Please can you help me to fix it? :)
    • Arfius said at 04/03, 2011
      Hi Leonard,
      seems that you have my same configuration.
      I resolved the cmake problem installing the last version (2.8.4) using the source code.
      I modified the opencv_cmake.sh how to explained Sergei L. some post above but I changed the version of arm, from armv6 to armv7.

      from Sergei L.'s post : (I replaced armv6->armv7)

      1) FLAGS="-miphoneos-version-min=${IPHONEOS_VERSION_MIN}" => FLAGS="-arch armv7 -miphoneos-version-min=${IPHONEOS_VERSION_MIN}"
      2) FLAGS="" => FLAGS="-arch i386"
    • Yasuhiro Yoshimura said at 04/03, 2011
      Hi, Arfius

      Thank you for your information!
      I will update my page to build on iOS SDK 4.3.
      http://bit.ly/hNNxKV

      Best regards,
      Yasuhiro Yoshimura
    • Leonard said at 04/05, 2011
      Great information, thanks :)

      FYI, I used this page to download precompiled libraries for 4.3 and they work really well: https://github.com/BloodAxe/opencv-ios-template-project (from computer-vision-talks).
    • Tyua said at 04/08, 2011
      if anyone fails to compile after modifying the architecture involved, you need to delete build_device directory everytime you modify opencv_cmake.sh and regenerate the files in. there is maybe a cleaner method, but this is the only solution i found till now.
    • Tyua said at 04/12, 2011
      anyone succeeded to compile openCV with clang ?
    • Sandra said at 04/13, 2011
      For anyone trying to build the libraries using the script and encountering the error: -mmacosx-version-min not allowed with -miphoneos-version-min

      Inspired from a discussion on http://www.vtk.org/Bug/view.php?id=10155#c19366 , here is a workaround to that cmake bug:

      In /opt/local/share/cmake-2.8/Modules/Platform/Darwin.cmake (or the equivalent file on your system and version of cmake), find where CMAKE_OSX_DEPLOYMENT_TARGET_DEFAULT is set, and put it inside a switch. I used IF(NOT CMAKE_OSX_ARCHITECTURES MATCHES "armv6" AND NOT CMAKE_OSX_ARCHITECTURES MATCHES "armv7")

    • Patrick said at 04/14, 2011
      Can you please post the sample code for 4.3? I'm using xcode 4 and I can't get it to work.
      Thanks!
    • Yoshimasa Niwa said at 04/17, 2011
      Hi, all. I've updated master branch to support latest iOS SDK 4.3, OpenCV 2.2 and Xcode 4. The precompilied binaries now include both armv7 and armv6, also fix memory leaks in background thread.
    • Haqn said at 04/18, 2011
      Nice job with the update Yoshimasa, thank you! keep going! =)
    • Leonard said at 04/19, 2011
      @Yoshimasa (or others if they wish to chip in!)

      The demo project is great and works fine, but for some of use newbies, how should we best go about taking the libraries and use them in our own new project?
    • Linus said at 04/19, 2011
      I agree with Leonard. I really need OpenCV in a project. A small guide to apply it in our own project would be sweet!
    • Yoshimasa Niwa said at 04/19, 2011
      Leonard, Linus: I see, that's what I should put on the page. The step by step guild might be helpful...?
    • Linus said at 04/19, 2011
      I totally missed that last "Use with your own project" part. Sorry about that.

      This step: "Add libopencv_core.a etc, from OpenCV lib directory..."

      How do you mean we should do that? In xcode 4.
    • Linus said at 04/19, 2011
      Got it working! Great job with this :) It seems awesome!
    • Linus said at 04/19, 2011
      Is it possible to use the C++ interface? "using namespace cv;" ?
    • Leonard said at 04/21, 2011
      @Yoshimasa Ahh yes sorry... missed that also! I now have it working in XCode 4 nicely.

      Is there any way of getting calib3d working with these libraries? I need to use cvFindFundamentalMat() and at the minute it simply won't find it
    • ken said at 04/27, 2011
      大変助かりました!
      ここの情報が無ければ確実に断念していました。
      本当にありがとうございます!!
    • AlexSD said at 05/02, 2011
      Hy, it's very great job, but how would you do to use OpenSurf library into iPhone??
    • ZY said at 05/02, 2011
      ちょうど欲しい情報でした!
      本当にありがとうございます。
    • AlexSD said at 05/02, 2011
      ....and also, where can i found a example of implementation? does exist ?
    • Technocore said at 05/04, 2011
      こんにちは。
      XcodeでOpenCVを実装する方法で悩んでいたら、この
      サイトを見つけました。
      すばらしいサンプルです。ありがとうございました。
      疑問点が一つあるのですが、サンプルではターゲットの
      ビルド設定でヘッダ、ライブラリ検索パスを2種類
      定義されています。(device用とsimulator用の2行)
      私のXcodeでは1行分しかスペースが無いのですが
      どうすれば2種類の設定ができるのでしょう?
      初歩的質問ですが、よろしかったら教えてください。
    • Florent Morin said at 05/08, 2011
      In build settings, you can have a problem during compilation if you have spaces in your project path.
      So, you need to append "[...]" in search path.
      ex. "$(SRCROOT)/opencv_simulator/include"
    • Yoshimasa Niwa said at 05/09, 2011
      Leonard: I didn't try calib3d yet...
      AlexSD: I've tried that, you can see the branch named "test_open_surf" on my github repository.
      Technocore: Xcode4であればマウスオーバーしたときに表示される+ボタンから追加できます。Xcode3でも似たような操作だったと思います。
      Florent: Good point! Thank you, I've updated master branch on the repository.
    • AlexSD said at 05/09, 2011
      "you can see the branch named "test_open_surf" on my github repository."

      I did not found on github =(, maybe it was removed! 
      thank u for your time
    • Ashraf said at 05/10, 2011
      Thank you for this topic it's very helpful.
      I'm new to iPhone programming and I have a problem that i need to use FAST but I can't seem to find it.
      I used to call it like this on windows cv::FAST().
      Hope you can help me and thanks in advance.
    • AlexSD said at 05/11, 2011
      ops, i found it, but the xcode proj does not work, it has an error with the "library -lcv" and i don't know where i can found it !!!
    • Marcelo said at 05/16, 2011
      Thank you for this blog, and your help!
      I was testing the iphone test SURF and i wastrying to save the SURF's features on the Documents directory in this way:

      //Get the documents directory:

      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

      NSString *documentsDirectory = [paths objectAtIndex:0];

      //making the file name to write the data to using the documents directory:

      NSString *fileName = [NSString :@"%@/Features.txt", documentsDirectory];

      //create content - four lines of text

      NSString *content = saveSurf(Features.txt,ipts);

      //save content to the documents directory

      [content writeToFile:fileName atomically:NO encoding:NSStringEncodingConversionAllowLossy error:nil];

      But it does not work, can anyone help me to find the problem?
    • Haqn said at 05/22, 2011
      Yoshima, how can i compile libcvaux.a with your script? I would be glad if you can tell me a little about it, thanks in advance.
    • sri said at 06/06, 2011
      i am unable to build static library.I am getting some error in terminal.and also should i apply patch?If dint go for patch will it work?thanks in advance
    • Chris said at 06/08, 2011
      Thanks for this great blog and source code!

      One question:

      How do I enable the "mthumb" option for ARMv7 only,
      if I want to use the commandline as you do (by modifying CFLAGS, no Xcode OpenCV project)?

      Thanks and greetings
      Chris
    • Chris said at 06/08, 2011
      I think I found something:

      -Xarch_armv7 -mthumb
    • Chris said at 06/08, 2011
      ...it worked!

      For reference:

      I checked the compiled library file the way they suggest here:

      http://stackoverflow.com/questions/5838374/how-can-i-check-if-a-3rd-party-static-library-for-the-iphone-sdk-is-compiled-for

      and there was 2 byte code (thumb) for ARMv7 (iPhone 3GS, 4, etc.) and 4 byte code (non-thumb) for ARMv6 (iPhone 2G, 3G).

      @Yoshima:

      Maybe this is a possible improvement for your sample/blog?
    • Barış said at 06/08, 2011
      Hi Yoshima,
      Thanks to your methods about transforming uiimage and iplimage, I am able to use them in many parts of my code and they work very well. But now I need different versions of these methods. In my application I have grayscaled uiimages, and I need to use opencv functions with these images. So I need to convert these grayscaled uiimage into grayscaled iplimage and viceversa. 
      Where should I make changes in your functions, I made some changes but it doesn't work..
    • hao said at 06/11, 2011
      Do you know if CreateIplImageFromUIImage respects ImageOrientation? I can't seem to find an easy way to rotate the internal bitmap data.
    • Chih Chung said at 06/23, 2011
      Hello, thanks very much for you sharing, it helped greatly. But could I ask a little question? In your latest version patch(for opencv-2.2.0), the calib3d.hpp was not built to a library file. If I want to build and use it, how could I do?
    • Sal Aguinaga said at 07/13, 2011
      Yoshima and others, I'm new to this type of programming ... So, why/when would I want compile openCV from source? It isn't clear to me. I would appreciate you or anyone else letting me know. --Thanks!
    • lin_jinxing said at 07/25, 2011
      Thank you. It works.
    • Kim said at 08/03, 2011
      Thank you for this work. but I have a question. while i'm using opencv on iPhone, I have a problem with cvGetPerspectiveTransform. is it ok with you guys? I cannot use this method. 
      the error message is "malloc: *** error for object 0x181744: incorrect checksum for freed object - object was probably modified after being freed.
      *** set a breakpoint in malloc_error_break to debug"
      but I dont know why this happens. 

      I just want to test this, so the code is not complex.

      CvPoint2D32f abSrc[4], abDst[4];
      abSrc[0] = cvPoint2D32f(0, 0);
      abSrc[1] = cvPoint2D32f(48, 0);
      abSrc[2] = cvPoint2D32f(48, 48);
      abSrc[3] = cvPoint2D32f(0, 48);

      abDst[0] = cvPoint2D32f(200, 100);
      abDst[1] = cvPoint2D32f(402, 101);
      abDst[2] = cvPoint2D32f(390, 305);
      abDst[3] = cvPoint2D32f(190, 301);

      CvMat *mHwi = cvCreateMat(3, 3, CV_64FC1);
      cvGetPerspectiveTransform(abSrc, abDst, mHwi);

      cvReleaseMat(&mHwi);
      are there anyone who has the same problem?
    • thoka5.someone said at 08/11, 2011
      Great article with really helpful and insightful comments, and corresponding suggestions ... will start with something really cool ... hope this info helps me out properly ...
    • Wallas said at 08/21, 2011
      Amazing! Really helpful!

      Thank you!
    • hw said at 08/28, 2011
      Hi. Firstly thank you for providing your code. I would like to ask a question regarding your function CreateIplImageFromUIImage. 
      In that function, you created an iplImage initially with 4 channels because it is assumed that the image in UIImage has a alpha channel. If we had preprocessed our image to remove the alpha channel, how should I modify your code? 
      I tried changing your code to create an iplimage with 3 channels and changed the alpha info to kCGImageAlphaNoneSkipLast but it crashed my app.

      The reason I'm doing this is to avoid the conversion from 4 channels to 3 channels which my profiler indicates is taking up a lot of time and my project requires things to run in real-time. 

      Thanks and sorry for the long post.
    • ken said at 09/28, 2011
      初めて質問させていただきます。
      当方の環境はXcode4、iOS4.3です。
      現在opencvを使ってipadのアプリを作ろうとしていてこのサイトに辿りつきました。サンプルソースをダウンロードしてipadの画面一杯に表示するためにtarget device familyを「iphone/ipad」に変更して実行した所、OpenCVTestViewController.mの191行目のshowInView:self.viewで下記のエラーが発生しています。「Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: view != nil'」
      解決策がわかる方いらっしゃいましたら、お教え願います。
    • zhou said at 09/30, 2011
      hi, Yoshimasa,now ,i have a question ,i want to take the gray UIImage direct to transform into gray IplImage ,i have tried many times ,but it's all failed,can u give me some ideas,thanks ...
    • Shri said at 09/30, 2011
      After spending over 30 hours looking at OpenCV and iOS project on all the other websites, this is the first place where I downloaded your project and "everything just worked". Thanks a bunch.
    • Lluis said at 10/22, 2011
      Hi! I found this very useful! Thanks a lot!
      However, I still need to get highgui compiled. I actually happen to need cvConvertImage! Any ideas on how to get around this?
    • Leo said at 11/10, 2011
      hi, this is just awesome help. I am a beginner and i got this error while "make -j 4" step.

      2.2.0/modules/core/include/opencv2/core/core.hpp:56,
      from /Users/Leo/Documents/openCVtest/iphone_opencv_test/OpenCV-2.2.0/modules/core/src/precomp.hpp:55,
      from /Users/Leo/Documents/openCVtest/iphone_opencv_test/OpenCV-2.2.0/modules/core/src/alloc.cpp:43:
      /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/include/c++/4.2.1/exception:40: error: expected declaration before end of line
      make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/src/alloc.o] Error 1
      make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
      make: *** [all] Error 2

      Does anyone know how to solve this? xCode 4.2
    • Daniel said at 11/16, 2011
      why I can not use cvLog() or cvLaplace()? Help please!
    • Stéphane Péchard said at 12/07, 2011
      For those interested, I've forked and kept up to date (OpenCV 2.3.1 + iOS SDK 5.0.1 + XCode 4.2.1 + Mac OS X 10.7 for the last version) the niw repository: https://github.com/stephanepechard/iphone_opencv_test

      @lluis: my last version get highgui to compile! I just had to remove some functions.
    • Ajay said at 01/20, 2012
      Yoshimasa, 

      Thanks for your demo. Really its amazing & a good tutorial for self-learner within iPhoneSDK !!!

      I tried to build the app from your sourcecode for the simulator as well as iPhone.It worked exactly as you described in your context.Now I want to use the same demo app detecting the Corners of the Page rather than the Human Face. I tried to make little bit changes but not able to get those working upto the Mark.

      Below are the methods for the contour where I assume, I should make some changes, but atlast no success.

      Contour Retrieving Functions

      int cvFindContours(IplImage* img, CvMemStorage* storage, CvSeq** firstContour, int headerSize=sizeof(CvContour), CvContourRetrievalMode mode=CV_RETR_LIST,CvChainApproxMethod method=CV_CHAIN_APPROX_SIMPLE);

      CvContourScanner cvStartFindContours(IplImage* img, CvMemStorage* storage, int headerSize, CvContourRetrievalMode mode, CvChainApproxMethod method );

      Can you please help me with some code to detect the Corner of the Paper inside a image, Any suggestions ?
    • Duncan C said at 02/09, 2012
      Thanks for posting this. I plan on downloading it and trying it out. Can you tell me how fast the face detection is compared to Apple's new Core Image face detection, set on low quality? I'm putting together an app where I want to be able to find faces in a live video feed. It's ok if the face detection runs in the background and lags behind the video frames somewhat, but if it's more than a second or so it won't be very useful.

      Does OpenCV use GPU acceleration, or is it purely run on the CPU? If it runs on the CPU I suspect it will not be able to compete with GPU-driven image processing.
    • Russell said at 02/15, 2012
      You can get help from our team of software development.Please check www.seasiaconsulting.com
     
     
  • 相关阅读:
    93. Restore IP Addresses
    92. Reverse Linked List II
    阿里巴巴 内推 面试
    hulu
    287. Find the Duplicate Number *HARD*
    89. Gray Code
    87. Scramble String *HARD* 动态规划
    84. Largest Rectangle in Histogram *HARD* -- 柱状图求最大面积 85. Maximal Rectangle *HARD* -- 求01矩阵中的最大矩形
    BZOJ2693jzptab
    最大公约数和
  • 原文地址:https://www.cnblogs.com/mfryf/p/2379339.html
Copyright © 2011-2022 走看看