博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用cmake建立工程链接OPENNI2
阅读量:4041 次
发布时间:2019-05-24

本文共 3780 字,大约阅读时间需要 12 分钟。

main.cpp

/*************************OpenNI2 Deep, Color and Fusion ImageAuthor: Xin Chen, 2013.2Blog: http://blog.csdn.net/chenxin_130*************************/#include 
#include
#include
#include "OpenNI.h"#include "opencv2/core/core.hpp"#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"using namespace std;using namespace cv;using namespace openni;void CheckOpenNIError( Status result, string status ){ if( result != STATUS_OK ) cerr << status << " Error: " << OpenNI::getExtendedError() << endl;}int main( int argc, char** argv ){ Status result = STATUS_OK; //OpenNI2 image VideoFrameRef oniDepthImg; VideoFrameRef oniColorImg; //OpenCV image cv::Mat cvDepthImg; cv::Mat cvBGRImg; cv::Mat cvFusionImg; cv::namedWindow("depth"); cv::namedWindow("image"); cv::namedWindow("fusion"); char key=0; //【1】 // initialize OpenNI2 result = OpenNI::initialize(); CheckOpenNIError( result, "initialize context" ); // open device Device device; result = device.open( openni::ANY_DEVICE ); //【2】 // create depth stream VideoStream oniDepthStream; result = oniDepthStream.create( device, openni::SENSOR_DEPTH ); //【3】 // set depth video mode VideoMode modeDepth; modeDepth.setResolution( 640, 480 ); modeDepth.setFps( 30 ); modeDepth.setPixelFormat( PIXEL_FORMAT_DEPTH_1_MM ); oniDepthStream.setVideoMode(modeDepth); // start depth stream result = oniDepthStream.start(); // create color stream VideoStream oniColorStream; result = oniColorStream.create( device, openni::SENSOR_COLOR ); // set color video mode VideoMode modeColor; modeColor.setResolution( 640, 480 ); modeColor.setFps( 30 ); modeColor.setPixelFormat( PIXEL_FORMAT_RGB888 ); oniColorStream.setVideoMode( modeColor);//【4】 // set depth and color imge registration mode if( device.isImageRegistrationModeSupported(IMAGE_REGISTRATION_DEPTH_TO_COLOR ) ) { device.setImageRegistrationMode( IMAGE_REGISTRATION_DEPTH_TO_COLOR ); } // start color stream result = oniColorStream.start(); while( key!=27 ) { // read frame if( oniColorStream.readFrame( &oniColorImg ) == STATUS_OK ) { // convert data into OpenCV type cv::Mat cvRGBImg( oniColorImg.getHeight(), oniColorImg.getWidth(), CV_8UC3, (void*)oniColorImg.getData() ); cv::cvtColor( cvRGBImg, cvBGRImg, CV_RGB2BGR ); cv::imshow( "image", cvBGRImg ); } if( oniDepthStream.readFrame( &oniDepthImg ) == STATUS_OK ) { cv::Mat cvRawImg16U( oniDepthImg.getHeight(), oniDepthImg.getWidth(), CV_16UC1, (void*)oniDepthImg.getData() ); cvRawImg16U.convertTo( cvDepthImg, CV_8U, 255.0/(oniDepthStream.getMaxPixelValue())); //【5】 // convert depth image GRAY to BGR cv::cvtColor(cvDepthImg,cvFusionImg,CV_GRAY2BGR); cv::imshow( "depth", cvDepthImg ); } //【6】 cv::addWeighted(cvBGRImg,0.5,cvFusionImg,0.5,0,cvFusionImg); cv::imshow( "fusion", cvFusionImg ); key = cv::waitKey(20); } //cv destroy cv::destroyWindow("depth"); cv::destroyWindow("image"); cv::destroyWindow("fusion"); //OpenNI2 destroy oniDepthStream.destroy(); oniColorStream.destroy(); device.close(); OpenNI::shutdown(); return 0;}

CMakeLIsts.txt

cmake_minimum_required(VERSION 2.8)project(TestOPENNI2)include_directories($ENV{OPENNI2_INCLUDE})link_directories($ENV{OPENNI2_REDIST})message($ENV{OPENNI2_INCLUDE})message($ENV{OPENNI2_REDIST})find_package(OpenCV REQUIRED)add_executable(${PROJECT_NAME} "main.cpp")target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} libOpenNI2.so )

你可能感兴趣的文章
当前主要目标和工作
查看>>
使用 Springboot 对 Kettle 进行调度开发
查看>>
一文看清HBase的使用场景
查看>>
解析zookeeper的工作流程
查看>>
搞定Java面试中的数据结构问题
查看>>
慢慢欣赏linux make uImage流程
查看>>
linux内核学习(7)脱胎换骨解压缩的内核
查看>>
以太网基础知识
查看>>
慢慢欣赏linux 内核模块引用
查看>>
kprobe学习
查看>>
慢慢欣赏linux phy驱动初始化2
查看>>
慢慢欣赏linux CPU占用率学习
查看>>
2020年终总结
查看>>
Homebrew指令集
查看>>
React Native(一):搭建开发环境、出Hello World
查看>>
React Native(二):属性、状态
查看>>
JSX使用总结
查看>>
React Native(四):布局(使用Flexbox)
查看>>
React Native(七):Android双击Back键退出应用
查看>>
Android自定义apk名称、版本号自增
查看>>