iPhoneでOpenCVを使う方法

Posted by Yoshimasa Niwa on 03/14, 2009

OpenCVはIntelが開発したコンピュータビジョンのライブラリで、例えば顔検出などを簡単に行うことができます。 覚え書きとして、OpenCVをiOS SDKをつかってiPhone上やiPadで使う方法を、ビルドスクリプトとデモアプリケーションつきでメモしておきます。 これらのサムネイルはデモアプリケーションのスクリーンショットです。

最新のOpenCVとiOS SDKに対応

プロジェクトをOpenCV 2.2.0、iOS SDK 4.3、Xcode4に対応しました (2011/4/17更新)。

ひとまず使ってみる

すべてのソースコードとリソースはgithubのレポジトリに公開されています。 簡単に使えるように、事前にコンパイルしたOpenCVのライブラリとヘッダファイルを入れてあります。 すでにgitがあるなら、githubからレポジトリをcloneしてください。ない場合は、githubのdownloadリンクからzipかtarをダウンロードして解凍してください。

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

ソースコードを手に入れたら、OpenCVTest.xcodeprojをXcodeで開いてビルドします。 デモアプリケーションがシミュレータと実機両方で動くことが確認できると思います。

OpenCVのライブラリをソースからビルドする

もちろんOpenCVのライブラリをソースからgccでクロスコンパイルすることもできます。 そのための補助スクリプトを追加してあります。 重要なことは、iOS SDKはダイナミックリンク(.frameworkのような)に対応していない点です。 コンパイルするときには静的なライブラリを作成し、アプリケーションに静的にリンクする必要があります。

  1. OpenCVのビルドにはCMakeが必要です。HomebrewMacPortsを利用してインストールするのが簡単です。

    # Homebrewを使う場合
    % brew install cmake
    # MacPortsを使う場合
    % sudo port install cmake
    

    もし最近のAppleのJavaアップデートをインストールしていたとすると、javadeveloper_10.6_10m3261.dmgのインストールを求められるかもしれません。 かなり変ですが、cmakeはjni.hが必要でそれは最近のJavaアップデートで消されてしまったようです。 一応、ここからダウンロードできますが、Apple Developer Connectionに登録する必要があると思います。 ちなみに、このパッケージはいろいろと余計な物もインストールします… 悩ましいですねえ。どうやら、AppleはJavaを消し去りたいようですね。 (2010/10/30更新)

  2. OpenCVのソースコードをSourceForgeからダウンロードしてください。OpenCV-2.2.0.tar.bz2でテストしてあります。

  3. OpenCVのソースコードをこのデモアプリケーションのディレクトリで展開してください。

    % tar xjvf OpenCV-2.2.0.tar.bz2
    
  4. OpenCVにiOS SDKでビルドできるようにパッチを当ててください

    % cd OpenCV-2.2.0
    % patch -p1 < ../OpenCV-2.2.0.patch
    
  5. iPhoneのシミュレータむけには以下の手順でビルドしてください。 ファイルはデフォルトではopencv_simulatorディレクトにインストールされます。 makeコマンドでは-jでCPUに応じてジョブ数を変更してください。 -jがないとすごく時間がかかります

    % cd .. # デモアプリケーションのディレクトリに戻る
    % mkdir build_simulator
    % cd build_simulator
    % ../opencv_cmake.sh Simulator ../OpenCV-2.2.0
    % make -j 4
    % make install
    
  6. iPhoneの実機むけには以下の手順でビルドしてください。 ファイルはopencv_deviceディレクトにインストールされます。

    % cd .. # デモアプリケーションのディレクトリに戻る
    % mkdir build_device
    % cd build_device
    % ../opencv_cmake.sh Device ../OpenCV-2.2.0
    % make -j 4
    % make install
    

ビルドサポートスクリプト

ビルドサポートスクリプトopencv_cmake.shはいくつかのオプションがあります。環境や目的に合わせて選択してください。 --helpオプションをつけるとすべてのオプションが見られます。

UIImageとIplImageの相互変換

OpenCVはIplImage構造体を処理に使いますが、iOS SDKはUIImageオブジェクトを描画に使います。 つまり、これらの相互変換が必要になるわけですが、ありがたい事にiOS SDKのAPIで可能です。

IplImageをUIImageから作成するには、このようにします。

// NOTE 戻り値は利用後cvReleaseImage()で解放してください
- (IplImage *)CreateIplImageFromUIImage:(UIImage *)image {
  // CGImageをUIImageから取得
  CGImageRef imageRef = image.CGImage;

  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  // 一時的なIplImageを作成
  IplImage *iplimage = cvCreateImage(
    cvSize(image.size.width,image.size.height), IPL_DEPTH_8U, 4
  );
  // CGContextを一時的なIplImageから作成
  CGContextRef contextRef = CGBitmapContextCreate(
    iplimage->imageData, iplimage->width, iplimage->height,
    iplimage->depth, iplimage->widthStep,
    colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault
  );
  // CGImageをCGContextに描画
  CGContextDrawImage(
    contextRef,
    CGRectMake(0, 0, image.size.width, image.size.height),
    imageRef
  );
  CGContextRelease(contextRef);
  CGColorSpaceRelease(colorSpace);

  // 最終的なIplImageを作成
  IplImage *ret = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 3);
  cvCvtColor(iplimage, ret, CV_RGBA2BGR);
  cvReleaseImage(&iplimage);

  return ret;
}

戻り値のIplImageは利用後にcvReleaseImageで解放することを忘れないでください!

UIImageをIplImageから作成するには、このようにします。

// NOTE IplImageは事前にRGBモードにしておいてください。
- (UIImage *)UIImageFromIplImage:(IplImage *)image {
  CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
  // CGImageのためのバッファを確保
  NSData *data =
    [NSData dataWithBytes:image->imageData length:image->imageSize];
  CGDataProviderRef provider =
    CGDataProviderCreateWithCFData((CFDataRef)data);
  // IplImageのデータからCGImageを作成
  CGImageRef imageRef = CGImageCreate(
    image->width, image->height,
    image->depth, image->depth * image->nChannels, image->widthStep,
    colorSpace, kCGImageAlphaNone|kCGBitmapByteOrderDefault,
    provider, NULL, false, kCGRenderingIntentDefault
  );
  // UIImageをCGImageから取得
  UIImage *ret = [UIImage imageWithCGImage:imageRef];
  CGImageRelease(imageRef);
  CGDataProviderRelease(provider);
  CGColorSpaceRelease(colorSpace);
  return ret;
}

これでOpenCVをiPhoneで使うことができます!

OpenCVのライブラリを自分のプロジェクトで使う際の注意点

デモアプリケーションのXcodeプロジェクトはOpenCVのライブラリを使うためにいくつか特別な設定を加えています。 もし、自分のプロジェクトでOpenCVのライブラリを使う場合は、デモアプリケーションのXcodeプロジェクトを参考に以下の設定を行ってください。

  • libopencv_core.aなどをOpenCVのデバイス用かシミュレータ用のlibディレクトリから追加してください。 実際に使われるファイルはLibrary Search Pathsで決定されますので、どちらでも構いません。
  • Accelerate.frameworkを追加してください。OpenCVの内部で利用しているライブラリが含まれています。
  • アクティブなターゲットを選択して情報パネルの「ビルド」タブを「情報を見る」メニューから開いてください。
    • -lstdc++-lzをOther Linker Flagsに追加してください。
    • OpenCVのincludeディレクトリへのパスをHeader Search Pathsにシミュレータ用とデバイス用に追加してください。
    • OpenCVのlibディレクトリをLibrary Search Pathsにシミュレータ用とデバイス用に追加してください。

変更履歴

  • 2011/04/17 - OpenCV 2.2.0とiOS SDK 4.3、Xcode 4に対応。コメントありがとう!
  • 2010/10/30 - 最近の状況に合わせて文章を変更。コメントありがとう!
  • 2010/08/22 - OpenCV 2.1.0とiOS SDK 4.0に対応
  • 2009/12/21 - Snow Leopardでの問題を修正。Hyonさん、ありがとう!
  • 2009/11/05 - OpenCV 2.0.0とiPhone SDK 3.xに対応
  • 2009/03/14 - OpenCV 1.1.0とiPhone SDK 2.x対応版を公開

ご支援のお願い

もしこのプロジェクトを気に入って頂けましたら、お気軽に以下のフォームからPayPalを通じてご支援いただけると幸いです。

ご支援

皆様のご支援に感謝いたします。

ライセンス

このサンプルMIT Licenseで公開しています。

Share

Comments

  • bluestone007さんのコメント 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
  • イグナチオさんのコメント 07/05, 2009
    この情報があると大変助かります、ありがとうございます!。opencvをダウンロードし解凍するとエラーがでますので、恐らく違うopencvのファイルだと思います。
    opencv-1.1pre1.tar.gz の具体的なリンクを教えていただけないでしょうか?
  • Yoshimasa Niwaさんのコメント 07/05, 2009
    > イグナチオ さん
    数日前のSourceforgeの改変で、ダウンロードリンクが変更になっており、Safariではダウンロードできなくなっています。opendv-1.1pre1.tar.gzはopencv-linuxの下にありますが、Firefoxを使うなどしてダウンロードしてください。
  • Keoさんのコメント 07/29, 2009
    Hi, Great stuff here. I was wondering if you got openCV's video capture api to work?
  • Dongpyo Hongさんのコメント 07/29, 2009
    It would be great if you share your sample code
  • Dongpyo Hongさんのコメント 07/29, 2009
    Whoops! You did ;-) I didn't realize the bottom link.
  • Yoshimasa Niwaさんのコメント 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さんのコメント 08/12, 2009
    助かったよ!

    Thanks for providing an example project for this! This is a big help.
  • jeffさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 10/01, 2009
    Anyone got a solution?! Yoshimasa please, could you help us?! how can we get it work on 3.1 sdk?
  • Ignacioさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 11/17, 2009
    Thank you very much! It's great for me ^_^
  • duongtuさんのコメント 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さんのコメント 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さんのコメント 11/17, 2009
    素晴らしいですね。参考にさせてもらいました。こういった情報があると助かります。どうもありがとうございます!
  • Mihaさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 12/04, 2009
    Has anyone tried using this with live video and reference frames instead of still images?
  • Giacomo Rizziさんのコメント 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さんのコメント 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さんのコメント 12/13, 2009
    jeff said at 09/23, 2009
    I got the armv6 to compile, but not the sim. anyone have any trouble with that? the error i get is ** No targets specified and no makefile found. Stop.

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

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

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

    Thanks!
  • Kevin Cainさんのコメント 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さんのコメント 12/21, 2009
    Just a simple note for maplevincent:

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

    % cd OpenCV-2.0.0
    % mkdir build_simulator
    --> % cd build_simulator
    % ../../configure_opencv
    % make
    % make install
  • Yoshimasa Niwaさんのコメント 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さんのコメント 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さんのコメント 12/21, 2009
    Hello, Yoshimasa,

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

    % ARCH=device ../../configure_opencv

    should be:

    % ../../configure_opencv ARCH=device

    as below:

    % cd OpenCV-2.0.0
    % mkdir build_device
    % cd build_device
    % ../../configure_opencv ARCH=device
    % make
    % make install
  • Kevin Cainさんのコメント 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さんのコメント 12/21, 2009
    Hi Giacomo,
    I tested on iPhone then OpenSURF works on my iPhone 3G though, it is super slow...
  • Yoshimasa Niwaさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 12/24, 2009
    Hi Kenny, You can ignore any warnings.
  • Kennyさんのコメント 12/24, 2009
    Thanks for your fast reply!
    This article really help me a lot
  • Hamken100perさんのコメント 12/25, 2009
    とても助かりました。ありがとうございました。
    HighguiのVideo writer関連が使えるかな、と思って試してみましたが、やっぱり無理でした。
  • Yoshimasa Niwaさんのコメント 12/25, 2009
    > Hamken100perさん
    そうですねー、そのあたりすこし頑張ればできると思っていますが、がんばらないとダメですね。そもそもAPIがまだ公式ではないので、なんとも言い難いところがありますが。
  • Forrestさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 01/29, 2010
    Very good example it is really helpful for understanding
  • Kennyさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 03/21, 2010
    thanxxxx
  • andreasvさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 04/07, 2010
    These instructions do not seem to work for OpenCV 2.1. Any ideas?
  • alejandroさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 07/06, 2010
    Nice work, will try on my iphone....
  • Dizietさんのコメント 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!
  • キム・テウさんのコメント 07/21, 2010
    "../../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さんのコメント 08/11, 2010
    iPhoneで、OpenCVを使用したいと思いまして、参考にさせていただきました。が、インストール途中の、../../configure_opencvを実行したところで、下記の様になり、先に進めません。


    ---> Computing dependencies for zlib
    ---> Cleaning zlib
    ueno-gi-no-macbook-pro:build_simulator ueno$ ../../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さんのコメント 08/12, 2010
    iPhone SDK、OpenCVそれぞれのバージョンアップについていけていません。特にOpenCVはビルド方法が異なるので厄介です。追々、それぞれに対応していきたいと思いますが、今暫くお待ち下さい。
  • nonnusさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 08/22, 2010
    Ahish Lal: Remove build_device dir then try again, I guess cmake is caching the settings for simulator.
  • Ashish Lalさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 09/14, 2010
    forget about my last comment, I found a work-around

    Thanks for your work!
  • iceさんのコメント 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さんのコメント 09/15, 2010
    I get same error.
    What's wrong? ..
  • AMさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 09/27, 2010
    I used git clone instead of downloading with browser and it started working
    Thanks for your help
  • EXcellさんのコメント 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さんのコメント 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さんのコメント 10/01, 2010
    has anyone tried compiling the nhocr?
  • Carlos Scheideggerさんのコメント 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さんのコメント 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さんのコメント 10/12, 2010
    what is -add_subdirectory(highgui) in OpenCV-2.1.0patch does?
  • りずさんのコメント 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さんのコメント 10/13, 2010
    I'm assuming you had a problem compiling the highgui.. so many dependencies..
  • johndoeさんのコメント 10/13, 2010
    Error from debugger: mi_cmd_stack_list_frames: Not enough frames in stack
  • Tinaさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 10/18, 2010
    dude, you got the digg it link wrong
    I digget it anyway with proper URL
    take care & thanks
  • Yoshimasa Niwaさんのコメント 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さんのコメント 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さんのコメント 10/20, 2010
    My friend could you cross compile the nhocr :-) its for japanese :-)
  • johndoeさんのコメント 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さんのコメント 10/20, 2010
    this has errors..
  • Fumi22さんのコメント 10/20, 2010
    I have a problem when I try to use: cvCreateGaussianBGModel

    The compiler say that symbol not exists..
    Your demo works perfect
  • りずさんのコメント 10/21, 2010
    Hi, Mark.

    Thanks to you, I compiled it successfully.
  • Lokeyさんのコメント 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さんのコメント 10/22, 2010
    hello Yoshimasa-san,Thanks for your reply.
    I set -lm -lz -lstdc++ options, and it working fine.

    thanks a lot.
  • Tinaさんのコメント 10/23, 2010
    Thanks to Mark, after upgrading the sdk for iOS4, I finally got it compiled successfully.
  • vcnepoさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 11/08, 2010
    Jakub: because we need BGR color order.
  • Ignacioさんのコメント 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さんのコメント 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さんのコメント 12/01, 2010
    Hi,

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

    Thanks,
  • Stéphane Péchardさんのコメント 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さんのコメント 12/06, 2010
    Stéphane: I'll update the code soon, thanks!
  • Cresさんのコメント 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 さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 01/09, 2011
    サンプルコードを拝見しました。

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

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

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

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

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

    add_subdirectory(calib3d) was commented
  • Juniorさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 03/09, 2011
    Hi, Leonard
  • Yasuhiro Yoshimuraさんのコメント 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さんのコメント 03/10, 2011
    いつも参考にさせていただいています。Xcode4にアップデートすると、デバイスで実行できなくなりました。これはcmakeの中身を変更してビルドし直さなければいけないのでしょうか?
  • Leonardさんのコメント 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 ../../OpenCV-2.2.0/
    Starting cmake...
    Target SDK = iPhoneSimulator
    iOS SDK Version = 4.2
    iOS Deployment Target = 4.2
    OpenCV Root = ../../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 ../../OpenCV-2.2.0/
    Starting cmake...
    Target SDK = iPhoneOS
    iOS SDK Version = 4.2
    iOS Deployment Target = 4.2
    OpenCV Root = ../../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.さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 03/14, 2011
    I got another error now in the
    >>make -j 4
  • noobさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 03/16, 2011
    Hmm I'll try pre-compiled ones. Thanks Leanord..
  • Haqnさんのコメント 03/17, 2011
    @Leonard: Could you work Yasuhiro's project with these libraries from the link?
  • Leonardさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 04/12, 2011
    anyone succeeded to compile openCV with clang ?
  • Sandraさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 04/18, 2011
    Nice job with the update Yoshimasa, thank you! keep going! =)
  • Leonardさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 04/19, 2011
    Got it working! Great job with this :) It seems awesome!
  • Linusさんのコメント 04/19, 2011
    Is it possible to use the C++ interface? "using namespace cv;" ?
  • Leonardさんのコメント 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さんのコメント 04/27, 2011
    大変助かりました!
    ここの情報が無ければ確実に断念していました。
    本当にありがとうございます!!
  • AlexSDさんのコメント 05/02, 2011
    Hy, it's very great job, but how would you do to use OpenSurf library into iPhone??
  • ZYさんのコメント 05/02, 2011
    ちょうど欲しい情報でした!
    本当にありがとうございます。
  • AlexSDさんのコメント 05/02, 2011
    ....and also, where can i found a example of implementation? does exist ?
  • Technocoreさんのコメント 05/04, 2011
    こんにちは。
    XcodeでOpenCVを実装する方法で悩んでいたら、この
    サイトを見つけました。
    すばらしいサンプルです。ありがとうございました。
    疑問点が一つあるのですが、サンプルではターゲットの
    ビルド設定でヘッダ、ライブラリ検索パスを2種類
    定義されています。(device用とsimulator用の2行)
    私のXcodeでは1行分しかスペースが無いのですが
    どうすれば2種類の設定ができるのでしょう?
    初歩的質問ですが、よろしかったら教えてください。
  • Florent Morinさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 06/08, 2011
    I think I found something:

    -Xarch_armv7 -mthumb
  • Chrisさんのコメント 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ışさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 07/25, 2011
    Thank you. It works.
  • Kimさんのコメント 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さんのコメント 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さんのコメント 08/21, 2011
    Amazing! Really helpful!

    Thank you!
  • hwさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 11/16, 2011
    why I can not use cvLog() or cvLaplace()? Help please!
  • Stéphane Péchardさんのコメント 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さんのコメント 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さんのコメント 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さんのコメント 02/15, 2012
    You can get help from our team of software development.Please check www.seasiaconsulting.com
  • 한국개발자さんのコメント 06/11, 2013
    당신의 포스팅이 우리팀의 개발에 큰 도움이 되었습니다. 감사하므니다.
  • Tomoさんのコメント 12/11, 2013
    こんにちは。初めまして。
    パッチをあてようとすると
    -bash: ../OpenCV-2.2.0.patch: No such file or directory
    とエラーが出てしまいます。
    どうすればよいのでしょうか?
  • jpさんのコメント 03/14, 2016
    Hi, am working on hybrid environment where i should target my app for ios using OpenCV framework. I tried adding OpenCV 3.1 in my Cordova environment but it throws architecture arm_64 error. Could some resolve this immediately pls.
お名前
メールアドレス
(任意)
ウェブサイト
(任意)
コメント