資源簡介
Kinect運用OpenNI產生點云
http://blog.csdn.net/opensource07/article/details/7804246

代碼片段和文件信息
#include?“DepthmapToPointCloud.h“
#include?
#include?
#include?
#define?TODEGREE?57.2957795 //?radian->degree
#define?PI?3.1415926
/**?
*?global?variable
*/
xn::Context?context;
xn::DepthGenerator?dethGenerator;
DepthmapPointCloud?cloud(context?dethGenerator);
/**?
*?OpenGL?drawing
*/
int?h_rotate_angle=0?v_rotate_angle=0; //?h:?horizontal??v:?vertical
GLfloat?cameraX=0.0f?cameraY=0.0f?cameraZ=0.0f; //?相機坐標位置
GLfloat?h_rotate_radianh_sin_value?h_cos_value; //?旋轉角度、對應角度sin值與cos值??
GLfloat?v_rotate_radianv_sin_value?v_cos_value;
const?GLfloat?origin_to_center?=?2.5f; //?坐標原點到gluLookAt函數中視線點center的距離
GLfloat?zoom_step?=?origin_to_center; //?縮放變量
void?OpenGL_init(void)
{
glClearColor(0.0f?0.0f?0.0f?1.0f); //?background?color:?white?
glShadeModel(GL_FLAT);
glClear(GL_COLOR_BUFFER_BIT);
}
//////////////////////////////////////
void?OpenGL_rending(void)
{
// GLshort?r=0?g=0?b=0;
glColor3f(1.0f?1.0f?1.0f);
glPointSize(0.1f);
glBegin(GL_POINTS);
for?(unsigned?int?i=0;?i {
//? if?(cloud.getPointCloudData()[i].Z?>=0.0f?&&?cloud.getPointCloudData()[i].Z?0.4f)?{?r=1.0f;?g=1.0f;?b=1.0f;?} //?白色
//? else?if?(cloud.getPointCloudData()[i].Z?>=?0.4f?&&?cloud.getPointCloudData()[i].Z?0.8f)?{?r=0.0f;?g=1.0f;?b=1.0f;?}??//?青色
//? else?if?(cloud.getPointCloudData()[i].Z?>=?0.8f?&&?cloud.getPointCloudData()[i].Z?1.2f)?{?r=1.0f;?g=0.0f;?b=1.0f;?}??//?洋紅
//? else?if?(cloud.getPointCloudData()[i].Z?>=?1.2f?&&?cloud.getPointCloudData()[i].Z?1.6f)?{?r=0.0f;?g=0.75f;?b=1.0f;?}?//?深天藍
//? else?if?(cloud.getPointCloudData()[i].Z?>=?1.6f?&&?cloud.getPointCloudData()[i].Z?2.0f)?{?r=1.0f;?g=0.27f;?b=0.0f;?}?//?橙紅
//? else?{?r=0.0f;?g=0.0f;?b=0.0f;?} //?黑色
//?深度圖形式表示
//? if?(cloud.getPointCloudData()[i].Z?>=?0.4)
//? r?=?g?=?b?=?(int)((cloud.getPointCloudData()[i].Z-0.4)*100)>>1;
//? else
//? r?=?g?=?b?=?255;
// glColor3b(r?g?b);
glVertex3f(cloud.getPointCloudData()[i].X?cloud.getPointCloudData()[i].Y?cloud.getPointCloudData()[i].Z);
}
glEnd();
cloud.updataPointCloud(); //?update?next?frame?cloudpoint?data
glFlush();
glutSwapBuffers();
}
/////////////////////////////////////
void?OpenGL_Idel()
{
OpenGL_rending(); //?刷新顯示
glClear(GL_COLOR_BUFFER_BIT);
}
/////////////////////////////////////
void?OpenGL_changeSize(int?w?int?h)
{
glViewport(0?0?GLsizei(w)?GLsizei(h));
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//? if?(w?<=?h) //?正交投影
//? glOrtho(-2.0?2.0?-2.0*(GLfloat)h/(GLfloat)w?2.0*(GLfloat)h/(GLfloat)w?-10.0?10.0);
//? else
//? glOrtho(-2.0*(GLfloat)w/(GLfloat)h?2.0*(GLfloat)w/(GLfloat)h?-2.0?2.0?-10.0?10.0);
gluPerspective(60.0?(GLfloat)w/(GLfloat)h?0.1f?50.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(cameraX?cameraY?cameraZ?0.0f?0.0f?0.1f?0.0f?1.0f?0.0f);
}
////////////////////////////////////
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-10-17?10:24??DepthmapToPointCloud_OpenGL\
?????文件?????????948??2012-07-29?10:52??DepthmapToPointCloud_OpenGL.sln
?????文件????????4095??2012-08-13?10:11??DepthmapToPointCloud_OpenGL\DepthmapToPointCloud.h
?????文件????????3706??2012-07-30?08:39??DepthmapToPointCloud_OpenGL\DepthmapToPointCloud_OpenGL.vcxproj
?????文件????????1088??2012-07-29?11:33??DepthmapToPointCloud_OpenGL\DepthmapToPointCloud_OpenGL.vcxproj.filters
?????文件?????????143??2012-07-29?10:52??DepthmapToPointCloud_OpenGL\DepthmapToPointCloud_OpenGL.vcxproj.user
?????文件????????6881??2012-08-02?11:10??DepthmapToPointCloud_OpenGL\PointCloudDisplay.cpp
評論
共有 條評論