11 Replies Latest reply on Sep 6, 2018 4:11 PM by MartyG

    How to find 3 or 5 center pixels from depth image


      Hi everyone,


      I am trying to find few center pixels from the depth image. I am trying to implement segmentation, I need to find distance of the segmented object.

      This is how I was thinking, this will work. while the colored image is used for segmentation, the full frame depth image will be used to find the distance.


      In my code below. I found the diagonal of the depth image, I am trying to find 3 or 5 pixels. I do not how to find the value from the array. I only have the index printed on my console.as print 40,35 but no value.

      I hope i did not confuse you. Everything is new to me.


      I have tried this;


        void SampleArrived(object sender, SampleArrivedEventArgs args)




              if (args.sample.Depth == null)







                  var depthImageArray = args.sample.Depth;

                  Debug.Log("my depth value is" + depthImageArray);

                  var diagonal = Math.Sqrt((depthWidth*depthWidth)+ (depthHeight*depthHeight))/2;

                  texPlugin.UpdateTextureNative(args.sample.Depth, depthTex2DPtr);


                  for (int y =0; y < diagonal; ++y)



                      for (int x = 0; x < diagonal; ++x)


                          Debug.Log(string.Format("print {0}, {1}", x, y ));

                          var path = (@"C:\Users\Admin\Downloads\builtin_shaders-5.2.2f1\DefaultResourcesExtra\Unlit\sample.txt");

                          var content = (string.Format("print {0}, {1}", x, y));

                          StreamWriter File = new StreamWriter(path)





                  Debug.Log("diagonal pixels"  + StreamType.ToIndex[40,35];