Community
cancel
Showing results for 
Search instead for 
Did you mean: 
nadiya_s_
Beginner
92 Views

Getting Null value from QueryVertices()

Hi TEam,

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
                       system.out.println(vertices[1].z);  //getting in console-  java.lang.NullPointerException
                        

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

thanks in advance.

 

regards,

Nadiya

 

0 Kudos
5 Replies
jb455
Valued Contributor II
92 Views

Are the values of dWidth and dHeight the same as cWidth and cHeight? I can see you've requested the colour and depth images to be the same size but if they're not, the vertices array will be initialised to the wrong size which would cause an error. So if you do:  PXCMPoint3DF32[] vertices = new PXCMPoint3DF32[dWidth * dHeight]; that may fix it.

Other ways I know of to get the vertices are ProjectColorToCamera and ProjectDepthToCamera.

Good luck!

krishna_m_1
Beginner
92 Views

hi,

I have no tried in java (am a c++ guy), I have a doubt as in (https://software.intel.com/en-us/forums/realsense/topic/611268)

do you get the color image mapped to depth with same field of view of depth? 

the format of depth and color that you pass is of type PIXEL_FORMAT_RGB32 and output is of type PIXEL_FORMAT_RGB24. is that true??

nadiya_s_
Beginner
92 Views

Hi James,

Thanks for your prompt reply. In our case cWidth & dWidth and cHeight & dHeight are same. While executing projection.QueryVertices(depth, vertices), i am getting PXCM_STATUS_NO_ERROR as output, but the as output we are getting vertices as null. so while executing vertices[1].z  getting null pointer exception. Is there anything that i m missing ??

If i use ProjectColorToCamera i need an array of depth coordinates in the Point3DF32 structure.ss i am not able to understand how to get the value. 

please help.thanks in advance

 

 

Regards, 

nadiya

jb455
Valued Contributor II
92 Views

Hmm, I can't see anything obvious, though I'm comparing with my C# code.

Bit of a long shot... are you getting this error on the first frame? If it's fine on the first frame, but null on subsequent frames, maybe you aren't disposing of all the images? That may cause some confusion (also lots of memory buildup)

Yeah, I thought it was pretty nonsensical that you need the depth image mapped to the colour image already to use ProjectColorToCamera.. Here's how I did it though (sorry, you'll have to translate from C#):

PXCMImage.ImageData mdata;
var mappedImage = projection.CreateDepthImageMappedToColor(depth, image);
mappedImage.AcquireAccess(PXCMImage.Access.ACCESS_READ, PXCMImage.PixelFormat.PIXEL_FORMAT_DEPTH, out mdata);
var mwidth = mappedImage.info.width;
var mheight = mappedImage.info.height;
mpitch = (Int32)(mdata.pitches[0] / 2.0);
var mappedPixels = mdata.ToShortArray(0, mwidth * mheight);
mappedImage.ReleaseAccess(mdata);
mappedImage.Dispose();

var cp = new PXCMPoint3DF32[cwidth * cheight];
var vertices = new PXCMPoint3DF32[cwidth * cheight];
for (int j = 0, k = 0; j < cheight; j++)
{
  for (int i = 0; i < cwidth; i++, k++)
  {
    cp = new PXCMPoint3DF32(i, j, mappedPixels[j * mpitch + i]);
  }
}
projection.ProjectColorToCamera(cp, cvp);
nadiya_s_
Beginner
92 Views

Hi James,

 Thanks for your promt reply....

I have tried ProjectColorToCamera  function to get expected result. But still i am getting null value in output array(cvp). There also  I am getting the same null value while extracting x value by using cvp[0].x

Can please tell me which way I am getting wrong.

Any help will be appreciated.Thanks in advance.

Reply