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. shell中的条件判断

    read命令 命令的语法: read [参数] 变量名 常用的参数如下: -t timeout 设定超时时间. -p prompt 设定提示信息,该提示信息将会显在光标前. 条件测试: 条件测试可以判 ...

  2. php类的属性

    属性声明是由关键字 public,protected 或者 private 开头,后面跟一个普通的变量声明来组成.属性的变量可以设置初始化的默认值,默认值必须是常量. class Car { //定义 ...

  3. php中引用符号(&amp;)的使用详解

    php的引用就是在变量或者函数.对象等前面加上&符号,在PHP 中引用的意思是:不同的名字访问同一个变量内容,下面介绍如何使用PHP的引用 与C语言中的指针是有差别的.C语言中的指针里面存储的 ...

  4. Linux-Tcp-IP

    /* tcpcli.c */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include ...

  5. 10g和11g,优化器对外连接的处理对比

    我反省,今天面试有个问题没有说清楚.我给出的结论(而且这个结论我验证过)是:不要使用不必要的外连接,举了下面这个例子却没有说清楚.虽然最近感冒,状态不是很好,但最擅长的东西都没有表达清楚,泪流满面啊: ...

  6. MySQL下Limit使用及性能分析

    对于一直用Oracle的我,今天可是非常诧异,MySQL中同一个函数在不同数量级上的性能居然差距如此之大. 先看表ibmng(id,title,info)  唯一  id key 索引title 先看 ...

  7. Entity Framework: 视图查询时重复返回第一行值, duplicate frst rows in resultset from a view

    http://blog.csdn.net/riverlau/article/details/7476449 1. 使用rownumber给view加上一个标示列 SELECT ROW_NUMBER() ...

  8. Quartz2D 备忘 + 学习

    Quartz2D Quartz2D是支持iOS和Mac系统的二维绘制引擎,它可以绘制: 绘制图形(图形,线条,圆等) 绘制文字 绘制/生成图片 读取/生成PDF 截图 Quartz2D主要功能就是以画 ...

  9. csu 10月 月赛 D 题 CX and girls

    Description CX是要赶去上课,为了不迟到必须要以最短的路径到达教室,同时CX希望经过的路上能看到的学妹越多越好.现在把地图抽象成一个无向图,CX从1点出发,教室在N号点,告诉每个点上学妹的 ...

  10. forward:hello 与 redirect:hello的区别

    对于某些Controller的处理方法,当返回值为String类型时,返回的结果中可能含有forward或redirect前缀: 如: @Controller @RequestMapping(&quo ...