Created
November 10, 2013 12:26
-
-
Save mountcedar/7397646 to your computer and use it in GitHub Desktop.
MavericksでのOpenCVとOpenNi2のインストールとビルドテスト ref: http://qiita.com/mountcedar/items/6d97efc0ea6c68c7674f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- CMakeLists.txt -*- | |
cmake_minimum_required (VERSION 2.8) | |
if(COMMAND cmake_policy) | |
cmake_policy(SET CMP0003 NEW) | |
endif(COMMAND cmake_policy) | |
# プログラムの追加 | |
add_executable(view main.cpp) | |
# CFLAGSの追加 | |
set (CMAKE_CXX_FLAGS "-Wall -g -I${PROJECT_SRC_DIRECTORY}/include") | |
# LDFLAGSの追加 | |
set (CMAKE_EXE_LINKER_FLAGS ${PLATFORM_LDFLAGS}) | |
# ライブラリの追加 | |
include_directories ( /usr/local/include/ni2 ) | |
link_directories ( /usr/local/lib/ni2 ) | |
find_package (OpenCV REQUIRED) | |
find_path(OpenNI2_INCLUDE_PATH NAMES OpenNI.h | |
PATH_SUFFIXES ni2 | |
PATHS | |
/usr/include | |
/usr/local/include) | |
find_library(OpenNI2_LIBRARY NAMES OpenNI2 libOpenNI2 | |
PATHS | |
/usr/lib | |
/usr/local/lib | |
/usr/local/lib/ni2) | |
target_link_libraries (view ${OpenCV_LIBS} ${OpenNI2_LIBRARY} stdc++) | |
# クリーン対象の追加 | |
set_directory_properties ( | |
PROPERTIES | |
ADDITIONAL_MAKE_CLEAN_FILES | |
"*~" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ xcode-select --install | |
$ brew install cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ brew tap homebrew/science | |
$ brew install opencv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ brew tap totakke/openni2 | |
$ brew install openni2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ brew install openni2-freenectdriver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir build | |
$ cd build | |
$ cmake .. | |
$ make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <OpenNI.h> | |
#include <opencv2/opencv.hpp> | |
#include <vector> | |
int main() | |
{ | |
try { | |
openni::OpenNI::initialize(); | |
openni::Device device; | |
int ret = device.open( openni::ANY_DEVICE ); | |
if ( ret != openni::STATUS_OK ) { | |
return -1; | |
} | |
openni::VideoStream colorStream; | |
colorStream.create(device, openni::SENSOR_COLOR); | |
colorStream.start(); | |
openni::Recorder recorder; | |
recorder.create( "kinect.oni" ); | |
recorder.attach( colorStream ); | |
recorder.start(); | |
std::vector<openni::VideoStream*> streams; | |
streams.push_back( &colorStream ); | |
cv::Mat colorImage; | |
while ( 1 ) { | |
int changedIndex; | |
openni::OpenNI::waitForAnyStream( &streams[0], streams.size(), &changedIndex ); | |
if ( changedIndex == 0 ) { | |
openni::VideoFrameRef colorFrame; | |
colorStream.readFrame( &colorFrame ); | |
if ( colorFrame.isValid() ) { | |
colorImage = cv::Mat( colorStream.getVideoMode().getResolutionY(), | |
colorStream.getVideoMode().getResolutionX(), | |
CV_8UC3, (char*)colorFrame.getData() ); | |
cv::cvtColor( colorImage, colorImage, CV_BGR2RGB ); | |
cv::imshow( "Color Camera", colorImage ); | |
} | |
} | |
int key = cv::waitKey( 10 ); | |
if ( key == 'q' ) { | |
break; | |
} | |
} | |
} | |
catch ( std::exception& ) { | |
std::cout << openni::OpenNI::getExtendedError() << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment