Xcode下C++开发OpenCV(来自国外网站)

懒得翻译了,看不懂的发邮件问我。

Installing OpenCV

Project Proposal and Update 1

1. For the first project, and possibly the second project as well, the team will get familiar with the OpenCV library, becoming familiar with OpenCV tools, and implementing OpenCV API’s in order to accomplish a few, small, tasks. Some of our ideas for implementation include:

-Ball tracking

-Eye tracking

- locating eye position on screen, blink to click

-Facial recognition

- expression recognition - happy, sad, wink, smile, brow raise

-individual face recognition/distinction

-Sign language alphabet

-Library of objects that can be recognized - iPhone, pen, flower...

-Flower recognition - different kinds of flowers.

-Animal recognition

-Sports - track player / puck, etc.

-Puzzle solver (this would be so cool!)

-iPhone integration

We will likely start from the top, some of the implementations above will clearly be beyond the scope of this project, but would nonetheless be cool in the long run.

2. The team has successfully installed OpenCV! This turned out to be much more challenging than either of us anticipated, as we found the instructions to be cryptic, and difficult to understand. All-in-all, it took about 5 hours to get the software installed. Because of this difficulty, the team decided to create a more straightforward tutorial, compiling information that we had found from multiple places online. This tutorial will be posted on stackoverflow.com so that people can see it if they google search. It is also included at the end of this write-up.
Now that we have the software installed, and the program working (we were successfully able to build and run a project in XCode that simply opened a new window), it is a matter of becoming more familiar with the OpenCV libraries. This will be accomplished by examining examples of code online, and become more familiar with the OpenCV API’s that will be most useful for our applications.

3. In addition to the 5-6 spent downloading the software, an additional hour was spent writing the tutorial, and an additional few hours spent becoming familiar with the basic commands of OpenCV. If time permits, we would be willing to spend more than 3-4 hours per week, as we have some extensive projects that would be cool to tackle.

4. In the next two weeks we would like to become familiar with the OpenCV library. We would like to implement at least one of the ideas described question 1, particularly the ball tracking (maybe narrow it to ball detection) or facial recognition (recognizing an image captured from a webcam, or recognizing faces in image files). We will focus on applications that do not involve many new API’s, and will focus on mastering a few at a time.

5. For the third report we would like to have an additional objective functioning, or perhaps we could go more in depth into the ball tracking or facial recognition. Recognizing facial gestures, such as a smile, a raised eyebrow, or a wink, are potential ideas that we would like to implement, although depending on the speed of our progression, this may wait until the final deliverable.
_________________________________________________________________________

Using OS X Lion, Xcode 4, and OpenCV 2.3.1

I found the website difficult to navigate through and the installation instructions cryptic, so when I finally go this thing working, I thought it would be nice to write some straightforward instructions for installing OpenCV and getting started with developing through Xcode.

I got most of this information from
http://opencv.willowgarage.com/wiki/UsingOpenCVUnderOSX
and
http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port
(look for this heading: “2. Build from source using the CMake build system (new)”)

Installation Instructions:

Install Xcode 4.3
Xcode 4.3 usually comes with OS X Lion. But if it is not installed, you need to go to the App Store and download it. Once it has installed open Xcode (its in your Applications folder) and go through the installer. Next, we need to install the Command Line Tools. In the menu bar, click Xcode > Preferences and in the Downloads toolbar menu, install the command line tools. This is documented here: http://guide.macports.org/chunked/installing.xcode.html

Download MacPorts
  • Download MacPorts. When you are at the link, click lion. Click the green download button, and wait for the annoying delay before it will actually start downloading:http://www.macports.org/install.php
Download OpenCV
  • Download OpenCV 2.3.1 for mac:http://sourceforge.net/projects/opencvlibrary/Uncompress it by double-clicking "OpenCV-2.3.1a.tar.bz2".Place the folder in your home directory (your home directory is titled your user name). Name the folder "opencv".

    Build OpenCV
    You can either run the executable file I wrote called “OpenCVInstaller” or just execute the commands in Terminal yourself, your choice. One caveat to be aware of is that to use the sudo commands (which will be used) you need to have a password on your computer. I ran into trouble with this. Terminal will not accept 0 characters as a password, so even though you log in just by pressing enter, you will need to (at least temporarily) set a password so that you type a password into Terminal when it asks for it. Also, (it goes without saying) you need to be an Admin.




    OpenCVInstaller Executable
    Download the executable file at the bottom of this page (the download button is on the bottom right). For some reason, you cannot download this as an executable, so you need to make it executable. Open Terminal (from your Applications folder), and change to the directory where the file is. If you put it on your Desktop, type:

    cd
    cd Desktop/
    Then to make the file executable, type:

    chmod +x "OpenCVInstaller"

    Then double click the file on your Desktop. Type your password into Terminal when it asks for it and it will start installing. Terminal will ask for your password a 2 times. This installation could take an hour or so, depending on the power of your computer. Once the installation is complete, skip to the "Xcode" section
    .If you encounter and error, you may need to go through and type the commands yourself.




    Execute Terminal Commands Yourself
    In Terminal (located in your applications folder), set MacPorts to auto-update by typing the bold statements below into the Terminal command line:


    cd
    sudo port -v selfupdate

    Install subversion:
    sudo port install subversion

    Install CMake:

    sudo port install cmake

    Then in Terminal, change your directory to the opencv folder:

    cd
    cd opencv

    In the opencv directory, install OpenCV. This will take a while.

    sudo port install opencv

    In the opencv folder, make a new directory called "build" (folder and directory are synonymous):

    mkdir build

    Make "build" your current directory:

    cd build

    These next few statements generate the OpenCV files we need. Randomly do this:

    cmake -G "Unix Makefiles" ..

    Check that opencv 2.3.1 was installed by looking back where it printed "General configuration".
    Then randomly do this:

    make -j8

    Then randomly do this:
    sudo make install


    Xcode:
OpenCV is now installed. Lets get an Xcode Project working with OpenCV. Open Xcode. 
  1. New  -> New Project -> Command Line Tool
  2. Name it and select C++
  3. Click on your project from the left menu. Click the build settings tab from the top. Filter all. Scroll to “Search Paths”. Under header search paths, for debug and release, set the path to /usr/local/include
  4. Click on your project from the left menu. File->New->New Group
  5. Name the group OpenCV Frameworks.
  6. Select the folder (group) you just labeled, “OpenCV Frameworks” in the left menu. Go to File -> add Files
  7. Type “/”, which will allow you to manually go to a folder. Go to ->/usr/local/lib
  8. Select both of these files,libopencv_core.dylib, libopencv_highgui.dylib, and click “Add”. (you may need to add other library files from this folder to run other code.)
  9. You must include this line of code in the beginning of your main.cpp file:


#include <opencv2/opencv.hpp>.
TEST CODE
Copy this code into your main.cpp file. It should open up a small window that is half shaded. (There may be some formatting errors in copy pasting this code into Xcode, but it should be easy to clean up.)

#include <iostream>
#include <opencv2/opencv.hpp>

int main( int argc, char *argv[])
{
    // Open the file.
   
    IplImage *img = cvCreateImage ( cvSize ( 100 , 200 ), IPL_DEPTH_8U , 3 ); //if (!img) {
   
    //    printf("Error: Couldn't open the image file.\n");
    //    return 1;
    //}
   
    // Display the image.
    cvNamedWindow ( "Image:" , CV_WINDOW_AUTOSIZE );
    cvShowImage ( "Image:" , img);
   
    // Wait for the user to press a key in the GUI window.
    cvWaitKey ( 0 );
    // Free the resources.
    cvDestroyWindow ( "Image:" );
    cvReleaseImage (&img);
   
    return 0 ;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值