資源簡介
快速實現kinect的三維重建,使用opencv和openGL和openNI實現三維重建。文中有一個CPP文件,是經過修改過的。絕對好用
代碼片段和文件信息
//?Kinect_glTest.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?
#include?“opencv2/highgui/highgui.hpp“
#include?“opencv2/imgproc/imgproc.hpp“
#include?“opencv2/calib3d/calib3d.hpp“
#include?
using?namespace?std;
using?namespace?cv;
//////////////////////////////////////////////////////////////////////////
//?
//---OpenGL?全局變量
float?xyzdata[480][640][3];
float?texture[480][640][3];
int?glWinWidth?=?640?glWinHeight?=?480;
int?width=640?height=480;
double?eyex?eyey?eyez?atx?aty?atz;??//?eye*?-?攝像機位置,at*?-?注視點位置
bool?leftClickHold?=?false?rightClickHold?=?false;
int?mxmy;? //?鼠標按鍵時在?OpenGL?窗口的坐標
int?ry=10?rx=10;????//?攝像機相對注視點的觀察角度
double?mindepth?maxdepth; //?深度數據的極值?
double?radius?=?4000.0; //?攝像機與注視點的距離
/************************************************************************/
/*???????????????????????????????????????????OpenGL響應函數?????????????????????????????????????????????????*/
/************************************************************************/
//////////////////////////////////////////////////////////////////////////
//?鼠標按鍵響應函數
void?mouse(int?button?int?state?int?x?int?y)
{
if(button?==?GLUT_LEFT_BUTTON)
{
if(state?==?GLUT_DOWN)
{
leftClickHold=true;
}
else
{
leftClickHold=false;
}
}
if?(button==?GLUT_RIGHT_BUTTON)
{
if(state?==?GLUT_DOWN)
{
rightClickHold=true;
}
else
{
rightClickHold=false;
}
}
}
//////////////////////////////////////////////////////////////////////////
//?鼠標運動響應函數
void?motion(int?x?int?y)
{
if(leftClickHold==true)
{
if(?x-mx?>?0?)
{
rx?+=?5;
}
else?if(?x-mx?0?)
{
rx?-=?5;
}
if(?y-my?>?0?)
{
ry?+=?5;
}
else?if(?y-my?0?)
{
ry?-=?5;
}
mx=x;
my=y;
glutPostRedisplay();
}
if(rightClickHold==true)
{
if(?y-my?>?0?)
{
radius?+=?100.0;
}
else?if(?y-my?0?)
{
radius?-=?100.0;
}
radius?=?std::max(?radius?100.0?);
mx=x;
my=y;
glutPostRedisplay();
}
}
//////////////////////////////////////////////////////////////////////////
//?三維圖像顯示響應函數
void?renderScene(void)?
{
//?clear?screen?and?depth?buffer
glClear?(GL_COLOR_BUFFER_BIT?);
//?Reset?the?coordinate?system?before?modifying?
glLoadIdentity();
//?set?the?camera?position
atx?=?0;
aty?=?0;
atz?=?(?mindepth?-?maxdepth?)?/?2.0f;
eyex?=?atx?+?radius?*?sin(?CV_PI?*?rx?/?180.0f?);?
eyey?=?atx?+?radius?*?cos(?CV_PI?*?ry/?180.0f?);?
eyez?=?atz?+?radius;
gluLookAt?(eyex?eyey?eyez?0?0?atz?0.0?1.0?0.0);
glRotatef(0010);
glRotatef(-180100);
float?xyz;
//?繪制圖像點云
glPointSize(1.0);?
glBegin(GL_POINTS);
for?(int?i=0;i for?(int?j=0;j //?color?interpolation?
glColor3f(texture[i][j][0]/255?texture[i][j][1]/255?texture[i][j][2]/255);
x=?xyzdata[i][j][0];
y=?xyzdata
- 上一篇:MIB文件解析
- 下一篇:C語言編寫圖形登陸界面
評論
共有 條評論