0

I want to find co-ordinates from QueryVertices() but getting null value while executing it.

Code 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

is there any other wat to get the co-ordinates.any help would be appreciated.

thanks in advance.

AmanS
  • 11
  • 4
  • 4
    Possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – Seth Apr 27 '16 at 08:51
  • Yes I know what is Null Pointer Exception...problem that i am facing here is that I am getting "NULL" in vertices array... – AmanS Apr 27 '16 at 11:30
  • Read something about arrays, it'll take you 5 minutes and you will probably figure out the issue even before that c: And think about the meaning of a NPE :) – Seth Apr 27 '16 at 13:07
  • I have a good understanding of arrays and NPE...I guess problem here is specific to the intel realsense api...maybe i'm not following the correct way...above code is working correctly and is not giving any exception/error otherwise, also queryvertices method is returning PXCM_STATUS_NO_ERROR – AmanS Apr 28 '16 at 17:26

1 Answers1

1

Your vertices array should be the size of the depth image, not the colour image, as you get a vertex for each pixel in the depth image. So use PXCMPoint3DF32[] vertices = new PXCMPoint3DF32[dWidth * dHeight]; instead.

jb455
  • 100
  • 1
  • 7
  • Hi @jb455 thanks for your reply...i changed ' PXCMPoint3DF32[] vertices = new PXCMPoint3DF32[cWidth * cHeight]; ' to ' PXCMPoint3DF32[] vertices = new PXCMPoint3DF32[dWidth * dHeight]; '...still i'm getting null values in vertices array... – AmanS May 13 '16 at 06:42
  • Hm, everything you've done is the same as I have in C#, which works... Another way of getting the vertices is using [projection.ProjectColorToCamera](https://software.intel.com/sites/landingpage/realsense/camera-sdk/v1.1/documentation/html/index.html?projectcolortocamera_pxcprojection.html), maybe try looking at that? It is a tad awkward though as you have to first map the depth values to the colour points for some reason. – jb455 May 13 '16 at 08:25