分享

[Wiki & 源码分享] 基于Kinect

 quasiceo 2015-12-10
前几天刚入手了期待已久的 Kinect ,用于实验室机器人项目的视觉导航与环境理解。目前完成了破解-->连接PC-->获取深度数据和图像数据-->三维点云显示 这几项基本工作,做了一些总结,写成 Wiki 和大家分享,详见 《 [url=http://www./index.php/%E5%9F%BA%E4%BA%8EKinect-OpenNI-OpenCV-OpenGL%E7%9A%84%E7%8E%AF%E5%A2%83%E4%B8%89%E7%BB%B4%E9%87%8D%E6%9E%84:1ripp78z]基于Kinect-OpenNI-OpenCV-OpenGL的环境三维重构[/url:1ripp78z] 》

主要是修改了 OpenCV 中的 cap_openni.cpp 和 highgui_c.hpp 两个文件,使得可通过 OpenCV 调整 Kinect 的深度摄像头的视角与彩色摄像头一致,从而可将深度图像和彩色图像很好地合并,然后用 OpenGL 显示出重构的环境三维效果,可以通过鼠标左右键的拖曳调整观察角度和观察距离。

所用版本是 OpenCV SVN、VS2008、OpenNI 1.0.0.23 。以下是项目源代码:
  1. // Kinect_glTest.cpp : Defines the entry point for the console application.
  2. //


  3. #include "stdafx.h"

  4. #include <GL/freeglut.h>
  5. #include "opencv2/highgui/highgui.hpp"
  6. #include "opencv2/imgproc/imgproc.hpp"
  7. #include "opencv2/calib3d/calib3d.hpp"
  8. #include <iostream>

  9. using namespace std;
  10. using namespace cv;

  11. #define SIGN(x) ( (x)<0 ? -1:((x)>0?1:0 ) )

  12. //////////////////////////////////////////////////////////////////////////
  13. //
  14. //---OpenGL 全局变量
  15. float xyzdata&#91;480&#93;&#91;640&#93;&#91;3&#93;;
  16. float texture&#91;480&#93;&#91;640&#93;&#91;3&#93;;
  17. int glWinWidth = 640, glWinHeight = 480;
  18. int width=640, height=480;
  19. double eyex, eyey, eyez, atx, aty, atz;  // eye* - 摄像机位置,at* - 注视点位置

  20. bool leftClickHold = false, rightClickHold = false;
  21. int mx,my;                         // 鼠标按键时在 OpenGL 窗口的坐标
  22. int ry = 90, rx = 90;    // 摄像机相对注视点的观察角度
  23. double mindepth, maxdepth;                // 深度数据的极值
  24. double radius = 6000.0;                // 摄像机与注视点的距离



  25. /************************************************************************/
  26. /*                                           OpenGL响应函数                                                 */
  27. /************************************************************************/

  28. //////////////////////////////////////////////////////////////////////////
  29. // 鼠标按键响应函数
  30. void mouse(int button, int state, int x, int y)
  31. {
  32.         if(button == GLUT_LEFT_BUTTON)
  33.         {
  34.                 if(state == GLUT_DOWN)
  35.                 {
  36.                         leftClickHold=true;
  37.                 }
  38.                 else
  39.                 {
  40.                         leftClickHold=false;
  41.                 }
  42.         }

  43.         if (button== GLUT_RIGHT_BUTTON)
  44.         {
  45.                 if(state == GLUT_DOWN)
  46.                 {
  47.                         rightClickHold=true;
  48.                 }
  49.                 else
  50.                 {
  51.                         rightClickHold=false;
  52.                 }
  53.         }
  54. }

  55. //////////////////////////////////////////////////////////////////////////
  56. // 鼠标运动响应函数
  57. void motion(int x, int y)
  58. {
  59.         int rstep = 5;
  60.         if(leftClickHold==true)
  61.         {
  62.                 if( abs(x-mx) > abs(y-my) )
  63.                 {
  64.                         rx += SIGN(x-mx)*rstep;   
  65.                 }
  66.                 else
  67.                 {
  68.                         ry -= SIGN(y-my)*rstep;   
  69.                 }
  70.                
  71.                 mx=x;
  72.                 my=y;
  73.                 glutPostRedisplay();
  74.         }

  75.         if(rightClickHold==true)
  76.         {
  77.                 radius += SIGN(y-my)*100.0;
  78.                 radius = std::max( radius, 100.0 );
  79.                 mx=x;
  80.                 my=y;
  81.                 glutPostRedisplay();
  82.         }
  83. }

  84. //////////////////////////////////////////////////////////////////////////
  85. // 三维图像显示响应函数
  86. void renderScene(void)
  87. {
  88.         // clear screen and depth buffer
  89.         glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  90.         // Reset the coordinate system before modifying
  91.         glLoadIdentity();       
  92.         // set the camera position
  93.         atx = 0.0f;
  94.         aty = 0.0f;
  95.         atz = ( mindepth - maxdepth ) / 2.0f;
  96.         eyex = atx + radius * sin( CV_PI * ry / 180.0f ) * cos( CV_PI * rx/ 180.0f );
  97.         eyey = aty + radius * cos( CV_PI * ry/ 180.0f );
  98.         eyez = atz + radius * sin( CV_PI * ry / 180.0f ) * sin( CV_PI * rx/ 180.0f );
  99.         gluLookAt (eyex, eyey, eyez, atx, aty, atz, 0.0, 1.0, 0.0);
  100.         glRotatef(0,0,1,0);
  101.         glRotatef(-180,1,0,0);
  102.        
  103.         // 对点云数据进行三角化
  104.         // 参考自:http://www./KB/openGL/OPENGLTG.aspx
  105.         // we are going to loop through all of our terrain's data points,
  106.         // but we only want to draw one triangle strip for each set along the x-axis.
  107.         for (int i = 0; i < height; i++)
  108.         {
  109.                 glBegin(GL_TRIANGLE_STRIP);
  110.                 for (int j = 0; j < width; j++)
  111.                 {
  112.                         // for each vertex, we calculate the vertex color,
  113.                         // we set the texture coordinate, and we draw the vertex.
  114.                         /*
  115.                            the vertexes are drawn in this order:

  116.                            0  ---> 1
  117.                                   /
  118.                                     /
  119.                               /
  120.                            2  ---> 3
  121.                         */
  122.                                
  123.                         // draw vertex 0
  124.                         glTexCoord2f(0.0f, 0.0f);
  125.                         glColor3f(texture&#91;i&#93;&#91;j&#93;&#91;0&#93;/255.0f, texture&#91;i&#93;&#91;j&#93;&#91;1&#93;/255.0f, texture&#91;i&#93;&#91;j&#93;&#91;2&#93;/255.0f);
  126.                         glVertex3f(xyzdata&#91;i&#93;&#91;j&#93;&#91;0&#93;, xyzdata&#91;i&#93;&#91;j&#93;&#91;1&#93;, xyzdata&#91;i&#93;&#91;j&#93;&#91;2&#93;);

  127.                         // draw vertex 1
  128.                         glTexCoord2f(1.0f, 0.0f);
  129.                         glColor3f(texture&#91;i+1&#93;&#91;j&#93;&#91;0&#93;/255.0f, texture&#91;i+1&#93;&#91;j&#93;&#91;1&#93;/255.0f, texture&#91;i+1&#93;&#91;j&#93;&#91;2&#93;/255.0f);
  130.                         glVertex3f(xyzdata&#91;i+1&#93;&#91;j&#93;&#91;0&#93;, xyzdata&#91;i+1&#93;&#91;j&#93;&#91;1&#93;, xyzdata&#91;i+1&#93;&#91;j&#93;&#91;2&#93;);

  131.                         // draw vertex 2
  132.                         glTexCoord2f(0.0f, 1.0f);
  133.                         glColor3f(texture&#91;i&#93;&#91;j+1&#93;&#91;0&#93;/255.0f, texture&#91;i&#93;&#91;j+1&#93;&#91;1&#93;/255.0f, texture&#91;i&#93;&#91;j+1&#93;&#91;2&#93;/255.0f);
  134.                         glVertex3f(xyzdata&#91;i&#93;&#91;j+1&#93;&#91;0&#93;, xyzdata&#91;i&#93;&#91;j+1&#93;&#91;1&#93;, xyzdata&#91;i&#93;&#91;j+1&#93;&#91;2&#93;);

  135.                         // draw vertex 3
  136.                         glTexCoord2f(1.0f, 1.0f);
  137.                         glColor3f(texture&#91;i+1&#93;&#91;j+1&#93;&#91;0&#93;/255.0f, texture&#91;i+1&#93;&#91;j+1&#93;&#91;1&#93;/255.0f, texture&#91;i+1&#93;&#91;j+1&#93;&#91;2&#93;/255.0f);
  138.                         glVertex3f(xyzdata&#91;i+1&#93;&#91;j+1&#93;&#91;0&#93;, xyzdata&#91;i+1&#93;&#91;j+1&#93;&#91;1&#93;, xyzdata&#91;i+1&#93;&#91;j+1&#93;&#91;2&#93;);
  139.                 }
  140.                 glEnd();
  141.         }
  142.         // enable blending
  143.         glEnable(GL_BLEND);

  144.         // enable read-only depth buffer
  145.         glDepthMask(GL_FALSE);

  146.         // set the blend function to what we use for transparency
  147.         glBlendFunc(GL_SRC_ALPHA, GL_ONE);

  148.         // set back to normal depth buffer mode (writable)
  149.         glDepthMask(GL_TRUE);

  150.         // disable blending
  151.         glDisable(GL_BLEND);

  152. /*         float x,y,z;
  153.         // 绘制图像点云
  154.         glPointSize(1.0);
  155.         glBegin(GL_POINTS);
  156.         for (int i=0;i<height;i++){
  157.                 for (int j=0;j<width;j++){
  158.                         // color interpolation
  159.                         glColor3f(texture&#91;i&#93;&#91;j&#93;&#91;0&#93;/255, texture&#91;i&#93;&#91;j&#93;&#91;1&#93;/255, texture&#91;i&#93;&#91;j&#93;&#91;2&#93;/255);
  160.                         x= xyzdata&#91;i&#93;&#91;j&#93;&#91;0&#93;;
  161.                         y= xyzdata&#91;i&#93;&#91;j&#93;&#91;1&#93;;
  162.                         z= xyzdata&#91;i&#93;&#91;j&#93;&#91;2&#93;;
  163.                         glVertex3f(x,y,z);
  164.                 }
  165.         }
  166.         glEnd(); */

  167.         glFlush();
  168.         glutSwapBuffers();
  169. }

  170. //////////////////////////////////////////////////////////////////////////
  171. // 窗口变化图像重构响应函数
  172. void reshape (int w, int h)
  173. {
  174.         glWinWidth = w;
  175.         glWinHeight = h;
  176.         glViewport (0, 0, (GLsizei)w, (GLsizei)h);
  177.         glMatrixMode (GL_PROJECTION);
  178.         glLoadIdentity ();
  179.         gluPerspective (45, (GLfloat)w / (GLfloat)h, 1.0, 15000.0);       
  180.         glMatrixMode (GL_MODELVIEW);
  181. }

  182. //////////////////////////////////////////////////////////////////////////
  183. // 载入三维坐标数据
  184. void load3dDataToGL(IplImage* xyz)
  185. {
  186.         CvScalar s;
  187.         //accessing the image pixels
  188.         for (int i=0;i<height;i++)
  189.         {
  190.                 for (int j=0;j<width;j++)
  191.                 {
  192.                         s=cvGet2D(xyz,i,j);                        // s.val&#91;0&#93; = x, s.val&#91;1&#93; = y, s.val&#91;2&#93; = z
  193.                         xyzdata&#91;i&#93;&#91;j&#93;&#91;0&#93; = s.val&#91;0&#93;;
  194.                         xyzdata&#91;i&#93;&#91;j&#93;&#91;1&#93; = s.val&#91;1&#93;;
  195.                         xyzdata&#91;i&#93;&#91;j&#93;&#91;2&#93; = s.val&#91;2&#93;;
  196.                 }
  197.         }
  198. }

  199. //////////////////////////////////////////////////////////////////////////
  200. // 载入图像纹理数据
  201. void loadTextureToGL(IplImage* img)
  202. {       
  203.         CvScalar ss;
  204.         //accessing the image pixels
  205.         for (int i=0;i<height;i++)
  206.         {
  207.                 for (int j=0;j<width;j++)
  208.                 {
  209.                         ss=cvGet2D(img,i,j);                        // ss.val&#91;0&#93; = red, ss.val&#91;1&#93; = green, ss.val&#91;2&#93; = blue
  210.                         texture&#91;i&#93;&#91;j&#93;&#91;2&#93; = ss.val&#91;0&#93;;
  211.                         texture&#91;i&#93;&#91;j&#93;&#91;1&#93; = ss.val&#91;1&#93;;
  212.                         texture&#91;i&#93;&#91;j&#93;&#91;0&#93; = ss.val&#91;2&#93;;
  213.                 }
  214.         }        
  215. }



  216. /************************************************************************/
  217. /*                                  colorizeDisparity                                                       */
  218. /*                          将视差图由灰度图转换为伪彩色图                                        */
  219. /************************************************************************/
  220. void colorizeDisparity( const Mat& gray0, Mat& rgb, double maxDisp=-1.f, float S=1.f, float V=1.f )
  221. {
  222.     CV_Assert( !gray0.empty() );
  223.         Mat gray;
  224.     if (gray0.type() == CV_32FC1)
  225.     {
  226.                 gray0.convertTo( gray, CV_8UC1 );
  227.     }
  228.         else if (gray0.type() == CV_8UC1)
  229.         {
  230.                 gray0.copyTo(gray);
  231.         }
  232.         else
  233.         {
  234.                 return;
  235.         }

  236.     if( maxDisp <= 0 )
  237.     {
  238.         maxDisp = 0;
  239.         minMaxLoc( gray, 0, &maxDisp );
  240.     }

  241.     rgb.create( gray.size(), CV_8UC3 );
  242.     rgb = Scalar::all(0);
  243.     if( maxDisp < 1 )
  244.         return;

  245.     for( int y = 0; y < gray.rows; y++ )
  246.     {
  247.         for( int x = 0; x < gray.cols; x++ )
  248.         {
  249.             uchar d = gray.at<uchar>(y,x);
  250.             unsigned int H = ((uchar)maxDisp - d) * 240 / (uchar)maxDisp;

  251.             unsigned int hi = (H/60) % 6;
  252.             float f = H/60.f - H/60;
  253.             float p = V * (1 - S);
  254.             float q = V * (1 - f * S);
  255.             float t = V * (1 - (1 - f) * S);

  256.             Point3f res;
  257.             
  258.             if( hi == 0 ) //R = V,        G = t,        B = p
  259.                 res = Point3f( p, t, V );
  260.             if( hi == 1 ) // R = q,        G = V,        B = p
  261.                 res = Point3f( p, V, q );
  262.             if( hi == 2 ) // R = p,        G = V,        B = t
  263.                 res = Point3f( t, V, p );
  264.             if( hi == 3 ) // R = p,        G = q,        B = V
  265.                 res = Point3f( V, q, p );
  266.             if( hi == 4 ) // R = t,        G = p,        B = V
  267.                 res = Point3f( V, p, t );
  268.             if( hi == 5 ) // R = V,        G = p,        B = q
  269.                 res = Point3f( q, p, V );

  270.             uchar b = (uchar)(std::max(0.f, std::min (res.x, 1.f)) * 255.f);
  271.             uchar g = (uchar)(std::max(0.f, std::min (res.y, 1.f)) * 255.f);
  272.             uchar r = (uchar)(std::max(0.f, std::min (res.z, 1.f)) * 255.f);

  273.             rgb.at<Point3_<uchar> >(y,x) = Point3_<uchar>(b, g, r);     
  274.         }
  275.     }
  276. }



  277. /************************************************************************/
  278. /*                                                 saveData                                                         */
  279. /*                                      保存当前画面的数据                                                  */
  280. /************************************************************************/
  281. void saveData(const char* filename, const Mat& mat, int flag = 0)               
  282. {
  283.         FILE* fp = fopen(filename, "wt");
  284.         if (3 != flag)
  285.         {
  286.                 fprintf(fp, "%02d\n", mat.rows);
  287.                 fprintf(fp, "%02d\n", mat.cols);
  288.         }
  289.         switch (flag)
  290.         {
  291.         case 0:
  292.                 for(int y = 0; y < mat.rows; y++)
  293.                 {
  294.                         for(int x = 0; x < mat.cols; x++)
  295.                         {
  296.                                 short depth = mat.at<short>(y, x);       
  297.                                 fprintf(fp, "%d\n", depth);
  298.                         }
  299.                 }
  300.                 break;
  301.         case 1:
  302.                 for(int y = 0; y < mat.rows; y++)
  303.                 {
  304.                         for(int x = 0; x < mat.cols; x++)
  305.                         {
  306.                                 uchar disp = mat.at<uchar>(y,x);
  307.                                 fprintf(fp, "%d\n", disp);
  308.                         }
  309.                 }
  310.                 break;
  311.         case 2:
  312.                 for(int y = 0; y < mat.rows; y++)
  313.                 {
  314.                         for(int x = 0; x < mat.cols; x++)
  315.                         {
  316.                                 float disp = mat.at<float>(y,x);
  317.                                 fprintf(fp, "%10.4f\n", disp);
  318.                         }
  319.                 }
  320.                 break;
  321.         case 3:
  322.                 for(int y = 0; y < mat.rows; y++)
  323.                 {
  324.                         for(int x = 0; x < mat.cols; x++)
  325.                         {
  326.                                 Vec3f point = mat.at<Vec3f>(y, x);        // Vec3f 是 template 类定义
  327.                                 fprintf(fp, "%f %f %f\n", point&#91;0&#93;, point&#91;1&#93;, point&#91;2&#93;);
  328.                         }
  329.                 }
  330.                 break;
  331.         case 4:
  332.                 imwrite(filename, mat);
  333.                 break;
  334.         default:
  335.                 break;
  336.         }

  337.         fclose(fp);
  338. }



  339. /************************************************************************/
  340. /*                                                    主程序                                                           */
  341. /************************************************************************/
  342. int main(int argc, char** argv)
  343. {
  344.         cout << "Kinect opening ..." << endl;
  345.     VideoCapture capture( CV_CAP_OPENNI );
  346.     cout << "done." << endl;
  347.        
  348.         if( !capture.isOpened() )
  349.     {
  350.         cout << "Can not open a capture object." << endl;
  351.         return -1;
  352.     }

  353.         capture.set(CV_CAP_OPENNI_DEPTH_GENERATOR_VIEW_POINT, 1.0);
  354.         double b = capture.get( CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE ); // mm
  355.         double F = capture.get( CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH ); // pixels

  356.         double q&#91;&#93; =
  357.         {
  358.                 1, 0, 0, -320.0,
  359.                 0, 1, 0, -240.0,
  360.                 0, 0, 0, F,
  361.                 0, 0, 1./b, 0               
  362.         };
  363.         Mat matQ(4, 4, CV_64F, q);

  364.         // Get max disparity
  365.         const int minDistance = 400; // mm
  366.         float maxDisparity = b * F / minDistance;

  367.         Mat depthMap;
  368.         Mat xyzMap;
  369.         Mat disparityMap;
  370.         Mat bgrImage;
  371.         Mat colorDisparityMap;
  372.         Mat validColorDisparityMap;
  373.        
  374.         // Print some avalible Kinect settings.
  375.     cout << "\nDepth generator output mode:" << endl <<
  376.             "FRAME_WIDTH    " << capture.get( CV_CAP_PROP_FRAME_WIDTH ) << endl <<
  377.             "FRAME_HEIGHT   " << capture.get( CV_CAP_PROP_FRAME_HEIGHT ) << endl <<
  378.             "FRAME_MAX_DEPTH    " << capture.get( CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH ) << " mm" << endl <<
  379.             "FPS    " << capture.get( CV_CAP_PROP_FPS ) << endl;

  380.     cout << "\nImage generator output mode:" << endl <<
  381.             "FRAME_WIDTH    " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_WIDTH ) << endl <<
  382.             "FRAME_HEIGHT   " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FRAME_HEIGHT ) << endl <<
  383.             "FPS    " << capture.get( CV_CAP_OPENNI_IMAGE_GENERATOR+CV_CAP_PROP_FPS ) << endl;


  384.         //////////////////////////////////////////////////////////////////////////
  385.         //***OpenGL Window
  386.         glutInit(&argc, argv);
  387.         glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
  388.         glutInitWindowPosition(10,320);
  389.         glutInitWindowSize(glWinWidth, glWinHeight);
  390.         glutCreateWindow("3D image");

  391.         //////////////////////////////////////////////////////////////////////////
  392.         //***OpenCV Window
  393.         namedWindow("Colorized disparity map", 1);
  394.         namedWindow("Color image", 1);

  395.         //////////////////////////////////////////////////////////////////////////
  396.         // 开始获取并显示 Kinect 图像
  397.         for(;;)
  398.         {
  399.                 depthMap.setTo(cvScalarAll(0));
  400.                 xyzMap.setTo(cvScalarAll(0));
  401.                 disparityMap.setTo(cvScalarAll(0));
  402.                 colorDisparityMap.setTo(cvScalarAll(0));
  403.                 validColorDisparityMap.setTo(cvScalarAll(0));
  404.                 bgrImage.setTo(cvScalarAll(0));

  405.                 // 抓取数据
  406.                 if( !capture.grab() )
  407.                 {
  408.                         cout << "Can not grab images." << endl;
  409.                         return -1;
  410.                 }

  411.                 // 读取深度数据
  412.                 capture.retrieve( depthMap, CV_CAP_OPENNI_DEPTH_MAP );
  413.                 minMaxLoc( depthMap, &mindepth, &maxdepth );
  414.                 // 读取视差数据
  415.                 capture.retrieve( disparityMap, CV_CAP_OPENNI_DISPARITY_MAP_32F );               
  416.         colorizeDisparity( disparityMap, colorDisparityMap, maxDisparity );
  417.         colorDisparityMap.copyTo( validColorDisparityMap, disparityMap != 0 );        
  418.                 imshow( "Colorized disparity map", validColorDisparityMap );
  419.                 // 读取彩色图像数据
  420.                 capture.retrieve( bgrImage, CV_CAP_OPENNI_BGR_IMAGE );
  421.                 imshow( "Color image", bgrImage );
  422.                 // 利用视差数据计算三维点云坐标
  423.                 cv::reprojectImageTo3D(disparityMap, xyzMap, matQ, true);

  424.                 //////////////////////////////////////////////////////////////////////////
  425.                 // OpenGL显示
  426.                 IplImage glXYZ = xyzMap;
  427.                 IplImage glTexture = bgrImage;
  428.                 load3dDataToGL(&glXYZ);                                // 载入环境三维点云
  429.                 loadTextureToGL(&glTexture);                // 载入纹理数据
  430.                 glutReshapeFunc (reshape);                        // 窗口变化时重绘图像
  431.                 glutDisplayFunc(renderScene);                // 显示三维图像      
  432.                 glutMouseFunc(mouse);                                // 鼠标按键响应
  433.                 glutMotionFunc(motion);                                // 鼠标移动响应
  434.                 glutPostRedisplay();                                                // 刷新画面
  435.                                
  436.                 //////////////////////////////////////////////////////////////////////////
  437.                 // 按键消息响应
  438.                 int c = cvWaitKey(30);
  439.                 if( c == 27 )
  440.                         break;
  441.                
  442.                 // OpenCV 处理键盘响应消息后,再显示 OpenGL 图像
  443.                 glutMainLoopEvent();
  444.         }                // 退出循环
  445.        
  446.         if(argc>1)
  447.         {
  448.                 saveData("C:\\Stereo IO Data\\xyz.txt",  xyzMap, 3);
  449.                 saveData("C:\\Stereo IO Data\\depth.txt", depthMap, 0 );
  450.                 saveData("C:\\Stereo IO Data\\disp.txt", disparityMap, 2 );
  451.                 Mat image;
  452.                 bgrImage.convertTo(image, CV_8UC3);
  453.                 //saveData("C:\\Stereo IO Data\\image.jpg", image, 4);
  454.                 imwrite("C:\\Stereo IO Data\\image.jpg", image);
  455.         }
  456.         return 0;
  457. }





复制代码



2#
发表于 2011-3-27 13:17:41 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

不错,只不过为什么有“破解”一步??




3#
 楼主| 发表于 2011-3-27 17:42:53 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

不错,只不过为什么有“破解”一步??
噢,其实破解就是安装 OpenNI 套件来驱动 Kinect,因为 Kinect 原本只是微软为 Xbox 360 的体感游戏而开发的,只能接 Xbox360 才能读取到数据,只有用 OpenNI 或 CL NUI Platform 等软件破解了 Kinect 的驱动,才能在普通电脑上读取 Kinect 的图像数据。据了解微软将在今年春季(4或5月份吧)推出 Kinect SDK 供科研和开发者使用,让更多的人挖掘 Kinect 的应用能力。




4#
发表于 2011-3-29 18:28:58 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

膜拜中.....




5#
发表于 2011-4-7 15:12:12 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

一直很关注你的blog,以前你的双目视觉项目一直不开放源码,学起来有些困难。期待你多一些的开源小项目,可以让这些关注你的 迷们,得到更多的学习机会。我的csdn号是:hufengjun,期待能加你一下。




6#
发表于 2011-4-10 11:02:36 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

我的程序里也遇到了这样一句话:
Vec3f point = mat.at<Vec3f>(y, x);   // Vec3f 是 template 类定义
请问这句代码是什么意思?




7#
发表于 2011-4-11 17:56:37 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

照代码做了,但在编译时出现
Error        9        error LNK2019: unresolved external symbol "void __cdecl cv::reprojectImageTo3D(class cv::Mat const &,class cv::Mat &,class cv::Mat const &,bool,int)" (?reprojectImageTo3D@cv@@YAXABVMat@1@AAV21@0_NH@Z) referenced in function _main        kinect_test.obj        kinect_test

希望能提供解决方法




8#
发表于 2011-4-11 18:26:54 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

照代码做了,但在编译时出现
Error        9        error LNK2019: unresolved external symbol "void __cdecl cv::reprojectImageTo3D(class cv::Mat const &,class cv::Mat &,class cv::Mat const &,bool,int)" (?reprojectImageTo3D@cv@@YAXABVMat@1@AAV21@0_NH@Z) referenced in function _main        kinect_test.obj        kinect_test

希望能提供解决方法

不好意思,是我自己程序里面没有添加#pragma comment(lib, "opencv_calib3d220d.lib")




9#
发表于 2011-4-11 19:28:29 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

我的程序里也遇到了这样一句话:
Vec3f point = mat.at<Vec3f>(y, x);   // Vec3f 是 template 类定义
请问这句代码是什么意思?
知道是什么意思了,但是现在不想用Mat这个类型,想用cvMat* mat,实现同样的功能该怎么写?
写成Vec3f point = CV_MAT_ELEM(mat,float,y,x);但是出错。




10#
发表于 2011-4-12 03:10:45 | 只看该作者

[Wiki & 源码分享] 基于Kinect-OpenNI-OpenCV-OpenGL的环境三

[quote="xzll77":2gdajja5]我的程序里也遇到了这样一句话:
Vec3f point = mat.at<Vec3f>(y, x);   // Vec3f 是 template 类定义
请问这句代码是什么意思?
知道是什么意思了,但是现在不想用Mat这个类型,想用cvMat* mat,实现同样的功能该怎么写?
写成Vec3f point = CV_MAT_ELEM(mat,float,y,x);但是出错。[/quote:2gdajja5]

关于cvMat 确实可以大家讨论一下~~~






    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多