2016-04-27 44 views
0

我想从QueryVertices()中找到坐标,但在执行时获取空值。在QueryVertices()中获取空值 - Intel Real Sense F200

代码Snippet-

public class CameraViewer2 
{  
    static int cWidth = 640; //Color image width 
    static int cHeight = 480; //Color image height 
    static int dWidth, dHeight; //depth image width and height 
    static boolean exit = false;//flag 

public static void main(String s[]) 
{ 

    PXCMSenseManager senseMgr = PXCMSenseManager.CreateInstance();  //Create a session manager instance 
    pxcmStatus sts = senseMgr.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, cWidth, cHeight); //STREAM_TYPE_COLOR The color stream. 
    sts = senseMgr.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH,cWidth,cHeight); //STREAM_TYPE_DEPTH The depth stream. 
    sts = senseMgr.Init(); //initialize the Manager 

    //getting the profile data 
    PXCMCapture.Device device = senseMgr.QueryCaptureManager().QueryDevice(); 
    PXCMCapture.Device.StreamProfileSet profiles = new PXCMCapture.Device.StreamProfileSet(); 
    device.QueryStreamProfileSet(profiles); 

    dWidth = profiles.depth.imageInfo.width; 
    dHeight = profiles.depth.imageInfo.height; 

    Listener listener = new Listener(); 

    if (sts == pxcmStatus.PXCM_STATUS_NO_ERROR) 
    { 
     while (listener.exit == false) 
     { 
      sts = senseMgr.AcquireFrame(true); //Wait until a new frame is available and lock it for processing. 
      if (sts == pxcmStatus.PXCM_STATUS_NO_ERROR) 
      { 
       PXCMCapture.Sample sample = senseMgr.QuerySample(); // retrieve the color and depth samples aligned 
       if (sample.color != null) 
       { 
        PXCMImage depth= sample.depth; 
        PXCMImage color= sample.color; 
        PXCMProjection projection=device.CreateProjection();// Create the PXCMProjection instance.    
        PXCMImage mappedColorImage=projection.CreateColorImageMappedToDepth(depth, color); 

        PXCMPoint3DF32[] vertices = new PXCMPoint3DF32[cWidth * cHeight]; 
        System.out.println(projection.QueryVertices(depth, vertices)); //getting in console- PXCM_STATUS_NO_ERROR 

是否有任何其他笏以取得共同ordinates.any帮助将不胜感激。

在此先感谢。

+4

可能重复[什么是空指针异常,以及如何解决它?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how -do-i-fix-it) – Seth

+0

是的,我知道什么是空指针异常...我在这里面临的问题是,我在顶点数组中获得“NULL”... – AmanS

+0

阅读关于数组的东西,它会带你5分钟,你甚至可能会在那之前找出问题c:并考虑NPE的含义:) – Seth

回答

1

当您获取深度图像中每个像素的顶点时,您的顶点数组应该是深度图像的大小,而不是彩色图像。所以请改用PXCMPoint3DF32[] vertices = new PXCMPoint3DF32[dWidth * dHeight];

+0

嗨@ jb455感谢您的回复...我cha 'PXCMPoint3DF32 [] vertices = new PXCMPoint3DF32 [cWidth * cHeight]; 'to'PXCMPoint3DF32 [] vertices = new PXCMPoint3DF32 [dWidth * dHeight]; '...仍然我得到顶点数组中的空值... – AmanS

+0

嗯,你做的所有事情都和我在C#中所做的一样,这是有效的......获得顶点的另一种方法是使用[投影。 ProjectColorToCamera](https://software.intel.com/sites/landingpage/realsense/camera-sdk/v1.1/documentation/html/index.html?projectcolortocamera_pxcprojection.html),也许尝试看看?虽然由于某些原因,您必须首先将深度值映射到颜色点,但这有些尴尬。 – jb455