【发布时间】:2016-04-27 08:49:27
【问题描述】:
我想从 QueryVertices() 中查找坐标,但在执行时得到空值。
代码片段-
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
还有其他方法可以获取坐标吗?任何帮助将不胜感激。
提前致谢。
【问题讨论】:
-
是的,我知道什么是空指针异常......我在这里面临的问题是我在顶点数组中得到“NULL”......
-
阅读一些有关数组的内容,这将花费您 5 分钟,您可能会在此之前弄清楚问题:并考虑 NPE 的含义 :)
-
我对数组和 NPE 有很好的理解...我猜这里的问题是特定于英特尔 realsense api...也许我没有遵循正确的方法...上面的代码正在工作正确并且没有给出任何异常/错误,否则 queryvertices 方法也返回 PXCM_STATUS_NO_ERROR