Mac下安装 OpenCV
1.下载Opencv:
2.使用CMake编译Opencv
3.测试~
cpp 代码:
Cmake 代码:
终端运行:
[img]http://dl.iteye.com/upload/attachment/0069/3373/f7e13c67-0ebf-387e-8ea8-93ad065d8a39.png[/img]
[img]http://dl.iteye.com/upload/attachment/0069/3375/28ca1db6-438d-3a45-8e33-572f435709c0.png[/img]
1.下载Opencv:
cd ~/<my_working _directory>
svn co http://code.opencv.org/svn/opencv/trunk2.使用CMake编译Opencv
cd ~/opencv
mkdir release
cd release
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install
3.测试~
cpp 代码:
#include <cv.h>
#include <highgui.h>
using namespace cv;
int main(int argc, char** argv) {
Mat image;
image = imread(argv[1], 1);
if(argc != 2 || !image.data) {
printf("No image data \n");
return -1;
}
namedWindow("Display Image", CV_WINDOW_AUTOSIZE);
imshow("Display Image", image);
waitKey(0);
return 0;
}
Cmake 代码:
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
终端运行:
stefan321@Lius-MacBook$ /usr/local/bin/cmake/bin/cmake .
-- The C compiler identification is GNU 4.2.1
-- The CXX compiler identification is Clang 3.1.0
-- 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: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as
cmake_minimum_required(VERSION 2.8)
should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run "cmake --help-policy CMP0000".
This warning is for project developers. Use -Wno-dev to suppress it.
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/stefan321/opencv
~/opencv
stefan321@Lius-MacBook$ make
Scanning dependencies of target DisplayImage
[100%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.o
Linking CXX executable DisplayImage
[100%] Built target DisplayImage
~/opencv
stefan321@Lius-MacBook$ ./DisplayImage 123.jpg
[img]http://dl.iteye.com/upload/attachment/0069/3373/f7e13c67-0ebf-387e-8ea8-93ad065d8a39.png[/img]
[img]http://dl.iteye.com/upload/attachment/0069/3375/28ca1db6-438d-3a45-8e33-572f435709c0.png[/img]
Mac下OpenCV安装与测试

本文详细介绍了如何在Mac操作系统上安装OpenCV,并通过一个简单的C++示例程序进行功能验证。首先从官方源码仓库下载OpenCV,然后利用CMake工具进行编译和安装。最后,通过一个读取并显示图片的示例程序来测试OpenCV是否成功安装。
625

被折叠的 条评论
为什么被折叠?



