HOWTO: Setup XCode 6.1 to work with OpenCV3 libraries

Overview

This post demonstrates how to setup your XCode IDE to work with openCV libraries on Yosemite. Initially XCode can be an intimidating environment, but past all the windows and complex sections, it boasts a number of beneficial features that aid and simplify programming – which for newcomers to openCV are a must. Features such as autocomplete and integrated compiler are extremely useful in simplifying compilation, speeding up programming time and clarifying how pieces of code fit together.

WARNING: This guide assumes you have compiled and installed openCV
It not, see this guide.

How To

Let’s begin.

  • Open XCode
  • Create New Project
  • Under OSX Application > Choose Command Line Tool
  • Give your application a name then Save

Assigning the Search Paths

To use the openCV libraries you will need to tell XCode where to find them.

  • Click the XCode project file in your inspector (which is the blue icon in the furthest left hand tab). You should now have three tabs in the centre window. Build Settings | Build Options | Build Rules
  • Click Build Settings
  • Scroll down until you find Search Paths
  • Double Click the Header Search Paths option, then Click the plus icon
  • Type in the following /usr/local/include
  • Next Double Click the Library Search Paths option, then Click the plus icon
  • Type in the following /usr/local/lib

Linking the Libraries

Now we need to tell XCode which libraries we want to build against. Still in Build Settings.

    • Scroll until you find Linking
    • Double Click Other Linker Flags and Click the plus icon
    • Copy and Paste the following, then press enter
-lopencv_calib3d -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videoio -lopencv_videostab

Setting the Build Path

XCode automatically stores the executable file in a derived data folder, we want to change it so that the executable is stored in your project directory.

  • Open XCode Preferences
  • Select Locations Tab
  • Click Advanced
  • Change the Location Button from Unique to Legacy

Build your Application

Now you are ready to build your application. In your main.cpp file, add the following code.
This is a sample application from the openCV package.

#include <opencv2/imgcodecs.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/highgui/highgui.hpp> #include <iostream>
#include <stdio.h> using namespace cv;
using namespace std; //hide the local functions in an anon namespace
namespace {
void help(char** av) {
cout << "The program captures frames from a video file, image sequence (01.jpg, 02.jpg ... 10.jpg) or camera connected to your computer." << endl
<< "Usage:\n" << av[] << " <video file, image sequence or device number>" << endl
<< "q,Q,esc -- quit" << endl
<< "space -- save frame" << endl << endl
<< "\tTo capture from a camera pass the device number. To find the device number, try ls /dev/video*" << endl
<< "\texample: " << av[] << "" << endl
<< "\tYou may also pass a video file instead of a device number" << endl
<< "\texample: " << av[] << " video.avi" << endl
<< "\tYou can also pass the path to an image sequence and OpenCV will treat the sequence just like a video." << endl
<< "\texample: " << av[] << " right%%02d.jpg" << endl;
} int process(VideoCapture& capture) {
int n = ;
char filename[];
string window_name = "video | q or esc to quit";
cout << "press space to save a picture. q or esc to quit" << endl;
namedWindow(window_name, WINDOW_KEEPRATIO); //resizable window;
Mat frame; for (;;) {
capture >> frame;
if (frame.empty())
break; imshow(window_name, frame);
char key = (char)waitKey(); //delay N millis, usually long enough to display and capture input switch (key) {
case 'q':
case 'Q':
case : //escape key
return ;
case ' ': //Save an image
sprintf(filename,"filename%.3d.jpg",n++);
imwrite(filename,frame);
cout << "Saved " << filename << endl;
break;
default:
break;
}
}
return ;
}
} int main(int ac, char** av) { if (ac != ) {
help(av);
return ;
}
std::string arg = av[];
VideoCapture capture(arg); //try to open string, this will attempt to open it as a video file or image sequence
if (!capture.isOpened()) //if this fails, try to open as a video camera, through the use of an integer param
capture.open(atoi(arg.c_str()));
if (!capture.isOpened()) {
cerr << "Failed to open the video device, video file or image sequence!\n" << endl;
help(av);
return ;
}
return process(capture);
}

Then hold CMD + B (This builds and compiles the application)
Go to your project folder. There should be a new folder called Debug, inside is your executable file.
Open Terminal then navigate to the folder, then simply type ./<yourprojectname> 0
This should open window and display the camera image.
And there you go!

15NOVEMBER 19, 2014 BY DAVID HAYLOCKOPENCVXCODEYOSEMITE

Post navigation

 

HOWTO: Setup XCode 6.1 to work with OpenCV3 libraries的更多相关文章

  1. Howto Setup yum repositories to update or install package from ISO CDROM Image

    Step # 1: Mount an ISO file Type the following command (replace iso file name with the actual iso fi ...

  2. HowTo: Xen 4.1.3 Windows 8 HVM domU with Intel HD4000 VGA Passthrough on Debian Wheezy

    http://linux-bsd-sharing.blogspot.com/2012/10/howto-xen-413-windows-8-hvm-domu-with.html Update 05/0 ...

  3. OpenSSL Command-Line HOWTO

    OpenSSL Command-Line HOWTO The openssl application that ships with the OpenSSL libraries can perform ...

  4. Server Name Indication(SNI)

    转载自: http://openwares.net/misc/server_name_indication.html Server Name Indication是用来改善SSL(Secure Soc ...

  5. ubuntu下解析udt数据包

    udt是通过udp进行端到端可靠传输的一个协议,有其默认拥塞控制算法. 之前ubuntu下wireshark的版本是1.10,不能直接解析udt数据包[1],升级到最新的2.0.0即可过滤udt数据包 ...

  6. Cocoapods的使用教程

    前言 对于iOS App的开发,几乎都采用了Cocoapods来管理第三方库,那么对于我们开发人员来说,这是必备技能,必须要掌握如何使用.这篇文章就是介绍如何安装和使用CocoaPods的. 这篇文章 ...

  7. Shell终端配置

    Shell终端配置 How to: Change / Setup bash custom prompt (PS1) 参考链接:https://www.cyberciti.biz/tips/howto- ...

  8. 【openwrt】再设置

    https://wiki.openwrt.org/zh-cn/doc/uci/network https://wiki.openwrt.org/zh-cn/doc/uci/wireless https ...

  9. Building gRPC Client iOS Swift Note Taking App

    gRPC is an universal remote procedure call framework developed by Google that has been gaining inter ...

随机推荐

  1. [GUIDE] How to install Scipy in Maya Windows 64 bit - Google 网上论坛 - Google Chrome

    I've seen a lot of queries about getting scipy working in Maya (Windows 64 bit) with a few not 100% ...

  2. c# 之 New新知

    本人从事.NET工作已经一段时间,毕业之前一直想着做C++的,后来因为各种原因(跟学校导师相关),走向了.NET之路,从而时不时补一下.net的基础知识,因为自己的.NET知识还不是很扎实.近期每天早 ...

  3. python 重载 __hash__ __eq__

    __author__ = 'root' from urlparse import urlparse class host_news(): def __init__(self, id, url): se ...

  4. vc6静态库的生成和调用

    转自vc6静态库的生成和调用 1.静态库的生成: 在vc6.0++中Ctrl+N选择Projects下的Win32 Static Library,Project name:SumLib,点击OK,下一 ...

  5. IntelliJ IDEA SVN的账号修改 信息清除

    来到编译器的setting设置 搜索subversion 点击subversion 找到下面的clear auth...按钮,点击一下 就可以了

  6. OA学习笔记-003-Hibernate3.6配置

    一.jar包:核心包, 必须包, jpa, c3p0, jdbc antlr-2.7.6.jarc3p0-0.9.1.jarcommons-collections-3.1.jardom4j-1.6.1 ...

  7. 【HDOJ】1695 GCD

    莫比乌斯反演简单题目. /* 1695 */ #include <iostream> #include <string> #include <map> #inclu ...

  8. git ignore 的使用

    http://www.barretlee.com/blog/2015/09/06/set-gitignore-after-add-file/ 需要注意的 **: 如果一个 pattern 以 ** 开 ...

  9. Ehcache详细解读(转)

    Ehcache 是现在最流行的纯Java开源缓存框架,配置简单.结构清晰.功能强大,最初知道它,是从Hibernate的缓存开始的.网上中文的EhCache材料 以简单介绍和配置方法居多,如果你有这方 ...

  10. statspack系列8

    原文:http://jonathanlewis.wordpress.com/2006/12/27/analysing-statspack-8/ 作者:Jonathan Lewis 在前面的关于stat ...