sudo apt-get update
sudo apt-get install g++ python libusb-1.0-0-dev freeglut3-dev
sudo apt-get install doxygen graphviz mono-complete
sudo apt-get install openjdk-7-jdk
git clone https://github.com/OpenNI/OpenNI.git
git clone git://github.com/avin2/SensorKinect.git (如果你的是kinect 下载此项)
git clone https://github.com/PrimeSense/Sensor.git (如果你的是xtion下载此项)
分别修改OpenNI 和Sensor
两个文件夹下的Platform.Arm 文件,将其中的
-mfloat-abi=softfp 改为 -mfloat-abi=hard
操作如下图
最后到 software/OpenNI/Platform/Linux/Bin/Arm-Release目录执行(其中的software为自己建立的文件夹)
cd ~/software/OpenNI/Platform/Linux/Bin/Arm-Release
sudo ./Sample-NiCRead
执行完毕,如果遇到 usb transfer timeout 的情况,则是树莓派的usb供电不足,不能启动xtion/kinect
解决方法:
cd /boot
sudo vim config.txt
在最后一行加入
max_usb_current=1
重启
sudo apt-get install libcv-dev
安装中如果遇到 Failed to fetch http://xxx.deb, 如下图所示的情况
解决方法:
执行:
1. wget http://xxx.deb
2. sudo dpkg -i xxx.deb
3. 重新执行
sudo apt-get install libcv-dev
新建loadimage.cpp
#include
#include
#include
#include
#include
#include
#include
using namespace std;
using namespace cv;
void CheckOpenNIError( XnStatus result, string status )
{
if( result != XN_STATUS_OK )
cerr << status << " Error: " << xnGetStatusString( result ) << endl;
}
int main( int argc, char** argv )
{
XnStatus result = XN_STATUS_OK;
xn::DepthMetaData depthMD;
xn::ImageMetaData imageMD;
namedWindow("depth",1);
namedWindow("image",1);
char key=0;
// context
xn::Context context;
result = context.Init();
CheckOpenNIError( result, "initialize context" );
// creategenerator
xn::DepthGenerator depthGenerator;
result = depthGenerator.Create( context );
CheckOpenNIError( result, "Create depth generator" );
xn::ImageGenerator imageGenerator;
result = imageGenerator.Create( context );
CheckOpenNIError( result, "Create image generator" );
//map mode
XnMapOutputMode mapMode;
mapMode.nXRes = 640;
mapMode.nYRes = 480;
mapMode.nFPS = 30;
result = depthGenerator.SetMapOutputMode( mapMode );
result = imageGenerator.SetMapOutputMode( mapMode );
depthGenerator.GetAlternativeViewPointCap().SetViewPoint( imageGenerator );
result = context.StartGeneratingAll();
Mat cvDepthImg;
Mat cvBGRImg;
context.WaitAndUpdateAll( );
while( (key!=27) && !(result = context.WaitNoneUpdateAll( )))
{
//get meta data
depthGenerator.GetMetaData(depthMD);
imageGenerator.GetMetaData(imageMD);
//OpenCV output
Mat cvDepthRawImg(depthMD.FullYRes(), depthMD.FullXRes(), CV_16UC1, (char *)depthMD.Data());
cvDepthRawImg.convertTo(cvDepthImg, CV_8U, 255.0/(depthMD.ZRes()));
imshow("depth", cvDepthImg);
Mat cvRGBImg(imageMD.FullYRes(), imageMD.FullXRes(), CV_8UC3, (char *)imageMD.Data());
cvtColor(cvRGBImg, cvBGRImg, CV_RGB2BGR);
imshow("image", cvBGRImg);
key=cvWaitKey(20);
}
//destroy
destroyWindow("depth");
destroyWindow("image");
context.StopGeneratingAll();
context.Release();
return 0;
}
新建makefile
CC = g++
TARGET = loadimage
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/ni
SRCS = loadimage.cpp
OBJS = $(SRCS:.cpp=.o)
# 库文件
DLIBS = -lopencv_core -lopencv_imgproc -lopencv_highgui -lOpenNI
# 链接可执行文件
$(TARGET):$(OBJS)
$(CC) -o $@ $^ $(DLIBS)
clean:
rm -rf $(TARGET) $(OBJS)
# 编译规则 $@代表目标文件 $<代表第一个依赖文件
%.o:%.cpp
$(CC) -o $@ -c $<