首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C++抽象误差

C++抽象误差
EN

Stack Overflow用户
提问于 2016-04-13 14:31:10
回答 1查看 742关注 0票数 0

解决方案

我在这里发布解决方案,这样你就不用一直滚动到底部了。另一个用户为这个问题向存储库添加了一个fix/修补程序。修复当前是不稳定的,因此您需要安装此项目的不稳定版本:

代码语言:javascript
复制
$ git clone https://github.com/avin2/SensorKinect
$ cd SensorKinect
$ git checkout unstable

问题

我正在尝试为我正在从事的业余项目手工编译SensorKinect./RedistMaker Arm的输出超过了30k SOF字符限制,所以我为那些好奇的人添加了作为对codepad.org的多行注释的整个输出。我提取了“重要”部分,并在下面添加了它们:

错误

代码语言:javascript
复制
$ ./RedistMaker Arm
Creating redist for Sensor v5.1.2.1
Cleaning previous outputs...
Building...
make: Entering directory `/home/ubuntu/kinect/SensorKinect/Platform/Linux/Build'
make -C XnCore CFG=Release
make -C XnDeviceSensorV2 CFG=Release


... output omitted here ...


In file included from /usr/include/ni/XnTypes.h:28:0,
                 from /usr/include/ni/XnModuleInterface.h:27,
                 from /usr/include/ni/XnModuleCppInterface.h:33,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorProductionNode.h:28,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorGenerator.h:28,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorMapGenerator.h:28,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorDepthGenerator.h:28,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorDepthGenerator.cpp:25:
../../../../Source/XnDeviceSensorV2/XnSensorDepthGenerator.cpp: In member function 'virtual XnSensorGenerator* XnExportedSensorDepthGenerator::CreateGenerator(xn::Context&, xn::Device&, XnDeviceBase*, const XnChar*)':
/usr/include/ni/XnOS.h:327:49: error: cannot allocate an object of abstract type 'XnSensorDepthGenerator'
  #define XN_NEW(type, ...)  new type(__VA_ARGS__)
                                                 ^
../../../../Source/XnDeviceSensorV2/XnSensorDepthGenerator.cpp:339:9: note: in expansion of macro 'XN_NEW'
  return XN_NEW(XnSensorDepthGenerator, context, sensor, pSensor, strStreamName);
         ^
In file included from ../../../../Source/XnDeviceSensorV2/XnSensorDepthGenerator.cpp:25:0:
../../../../Source/XnDeviceSensorV2/XnSensorDepthGenerator.h:39:7: note:   because the following virtual functions are pure within 'XnSensorDepthGenerator':
 class XnSensorDepthGenerator : 
       ^
In file included from ../../../../Source/XnDeviceSensorV2/XnSensorProductionNode.h:28:0,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorGenerator.h:28,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorMapGenerator.h:28,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorDepthGenerator.h:28,
                 from ../../../../Source/XnDeviceSensorV2/XnSensorDepthGenerator.cpp:25:
/usr/include/ni/XnModuleCppInterface.h:220:20: note:    virtual XnStatus xn::ModuleAlternativeViewPointInterface::GetPixelCoordinatesInViewPoint(xn::ProductionNode&, XnUInt32, XnUInt32, XnUInt32&, XnUInt32&)
   virtual XnStatus GetPixelCoordinatesInViewPoint(ProductionNode& other, XnUInt32 x, XnUInt32 y, XnUInt32& altX, XnUInt32& altY) = 0;
                    ^
make[1]: *** [Arm-Release/XnSensorDepthGenerator.o] Error 1

... more output omitted here ...

具有abstract错误的文件是。它在github上,下面是代码本身:

XnSensorDepthGenerator.cpp

代码语言:javascript
复制
/****************************************************************************
*                                                                           *
*  PrimeSense Sensor 5.x Alpha                                              *
*  Copyright (C) 2011 PrimeSense Ltd.                                       *
*                                                                           *
*  This file is part of PrimeSense Sensor.                                  *
*                                                                           *
*  PrimeSense Sensor is free software: you can redistribute it and/or modify*
*  it under the terms of the GNU Lesser General Public License as published *
*  by the Free Software Foundation, either version 3 of the License, or     *
*  (at your option) any later version.                                      *
*                                                                           *
*  PrimeSense Sensor is distributed in the hope that it will be useful,     *
*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the             *
*  GNU Lesser General Public License for more details.                      *
*                                                                           *
*  You should have received a copy of the GNU Lesser General Public License *
*  along with PrimeSense Sensor. If not, see <http://www.gnu.org/licenses/>.*
*                                                                           *
****************************************************************************/
//---------------------------------------------------------------------------
// Includes
//---------------------------------------------------------------------------
#include "XnSensorDepthGenerator.h"
#include <XnOpenNI.h>
#include <XnOS.h>
#include <XnPsVersion.h>
#include <XnCommon.h>
#include <math.h>

//---------------------------------------------------------------------------
// XnSensorDepthGenerator class
//---------------------------------------------------------------------------

XnSensorDepthGenerator::XnSensorDepthGenerator(xn::Context& context, xn::Device& sensor, XnDeviceBase* pSensor, const XnChar* strStreamName) :
    XnSensorMapGenerator(context, sensor, pSensor, strStreamName),
    m_hRWPropCallback(NULL)
{
}

XnSensorDepthGenerator::~XnSensorDepthGenerator()
{
    if (m_hRWPropCallback != NULL)
    {
        UnregisterFromProps(m_hRWPropCallback);
    }
}

XnStatus XnSensorDepthGenerator::Init()
{
    XnStatus nRetVal = XN_STATUS_OK;

    nRetVal = XnSensorMapGenerator::Init();
    XN_IS_STATUS_OK(nRetVal);

    const XnChar* aProps[] = 
    {
        XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE,
        XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE,
        NULL
    };

    m_hRWPropCallback;
    nRetVal = RegisterToProps(RealWorldTranslationPropChanged, this, m_hRWPropCallback, aProps);
    XN_IS_STATUS_OK(nRetVal);

    nRetVal = UpdateRealWorldTranslationData();
    if (nRetVal != XN_STATUS_OK)
    {
        UnregisterFromProps(m_hRWPropCallback);
        m_hRWPropCallback = NULL;
        return (nRetVal);
    }

    return (XN_STATUS_OK);
}

XnBool XnSensorDepthGenerator::IsCapabilitySupported(const XnChar* strCapabilityName)
{
    return (strcmp(strCapabilityName, XN_CAPABILITY_USER_POSITION) == 0 ||
        strcmp(strCapabilityName, XN_CAPABILITY_ALTERNATIVE_VIEW_POINT) == 0 ||
        strcmp(strCapabilityName, XN_CAPABILITY_FRAME_SYNC) == 0 ||
        XnSensorMapGenerator::IsCapabilitySupported(strCapabilityName));
}

XnDepthPixel* XnSensorDepthGenerator::GetDepthMap()
{
    return (XnDepthPixel*)m_pStreamData->pData;
}

XnDepthPixel XnSensorDepthGenerator::GetDeviceMaxDepth()
{
    XnUInt64 nValue;
    m_pSensor->GetProperty(m_strModule, XN_STREAM_PROPERTY_DEVICE_MAX_DEPTH, &nValue);
    return (XnDepthPixel)nValue;
}

void XnSensorDepthGenerator::GetFieldOfView(XnFieldOfView& FOV)
{
    FOV = m_FOV;
}

XnStatus XnSensorDepthGenerator::RegisterToFieldOfViewChange(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
{
    return m_fovChangedEvent.Register(handler, pCookie, hCallback);
}

void XnSensorDepthGenerator::UnregisterFromFieldOfViewChange(XnCallbackHandle hCallback)
{
    m_fovChangedEvent.Unregister(hCallback);
}

XnStatus XnSensorDepthGenerator::UpdateRealWorldTranslationData()
{
    XnStatus nRetVal = XN_STATUS_OK;

    XnUInt64 nZPD;
    nRetVal = GetIntProperty(XN_STREAM_PROPERTY_ZERO_PLANE_DISTANCE, nZPD);
    XN_IS_STATUS_OK(nRetVal);

    XnDouble fZPPS;
    nRetVal = GetRealProperty(XN_STREAM_PROPERTY_ZERO_PLANE_PIXEL_SIZE, fZPPS);
    XN_IS_STATUS_OK(nRetVal);

    m_FOV.fHFOV = 2*atan(fZPPS*XN_SXGA_X_RES/2/nZPD);
    m_FOV.fVFOV = 2*atan(fZPPS*XN_VGA_Y_RES*2/2/nZPD);

    nRetVal = m_fovChangedEvent.Raise();
    XN_IS_STATUS_OK(nRetVal);

    return (XN_STATUS_OK);
}

void XnSensorDepthGenerator::RealWorldTranslationPropChanged(void* pCookie)
{
    XnSensorDepthGenerator* pThis = (XnSensorDepthGenerator*)pCookie;
    pThis->UpdateRealWorldTranslationData();
}

XnUInt32 XnSensorDepthGenerator::GetSupportedUserPositionsCount()
{
    return 4;
}

XnStatus XnSensorDepthGenerator::SetUserPosition(XnUInt32 nIndex, const XnBoundingBox3D& Position)
{
    // set (we only support Z boxing for now)
    XnDepthAGCBin bin;
    bin.nBin = (XnUInt16)nIndex;
    bin.nMin = (XnUInt16)Position.LeftBottomNear.Z;
    bin.nMax = (XnUInt16)Position.RightTopFar.Z;
    return m_pSensor->SetProperty(m_strModule, XN_STREAM_PROPERTY_AGC_BIN, XN_PACK_GENERAL_BUFFER(bin));
}

XnStatus XnSensorDepthGenerator::GetUserPosition(XnUInt32 nIndex, XnBoundingBox3D& Position)
{
    XnStatus nRetVal = XN_STATUS_OK;

    // get
    XnDepthAGCBin bin;
    bin.nBin = (XnUInt16)nIndex;
    nRetVal =  m_pSensor->GetProperty(m_strModule, XN_STREAM_PROPERTY_AGC_BIN, XN_PACK_GENERAL_BUFFER(bin));
    XN_IS_STATUS_OK(nRetVal);

    XnMapOutputMode MapOutputMode;
    nRetVal = GetMapOutputMode(MapOutputMode);
    XN_IS_STATUS_OK(nRetVal);

    // we only support Z position for now
    Position.LeftBottomNear.Z = bin.nMin;
    Position.RightTopFar.Z = bin.nMax;
    Position.LeftBottomNear.X = 0;
    Position.RightTopFar.X = (XnFloat)(MapOutputMode.nXRes - 1);
    Position.LeftBottomNear.Y = 0;
    Position.RightTopFar.Y = (XnFloat)(MapOutputMode.nYRes - 1);

    return (XN_STATUS_OK);
}

XnStatus XnSensorDepthGenerator::RegisterToUserPositionChange(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
{
    const XnChar* aProps[] = 
    {
        XN_STREAM_PROPERTY_AGC_BIN,
        NULL
    };

    return RegisterToProps(handler, pCookie, hCallback, aProps);
}

void XnSensorDepthGenerator::UnregisterFromUserPositionChange(XnCallbackHandle hCallback)
{
    UnregisterFromProps(hCallback);
}

XnBool XnSensorDepthGenerator::IsSensorImageNode(xn::ProductionNode& OtherNode)
{
    xn::NodeInfo info = OtherNode.GetInfo();

    XnVersion Version;
    Version.nMajor = XN_PS_MAJOR_VERSION;
    Version.nMinor = XN_PS_MINOR_VERSION;
    Version.nMaintenance = XN_PS_MAINTENANCE_VERSION;
    Version.nBuild = XN_PS_BUILD_VERSION;

    // check if this view point is image from this DLL
    if (info.GetDescription().Type != XN_NODE_TYPE_IMAGE ||
        strcmp(info.GetDescription().strName, XN_DEVICE_NAME) != 0 ||
        strcmp(info.GetDescription().strVendor, XN_VENDOR_PRIMESENSE) != 0 ||
        xnVersionCompare(&info.GetDescription().Version, &Version) != 0)
    {
        return FALSE;
    }

    // check if it uses the same device
    xn::NodeInfoList needed = info.GetNeededNodes();
    for (xn::NodeInfoList::Iterator it = needed.Begin(); it != needed.End(); ++it)
    {
        if ((*it).GetDescription().Type == XN_NODE_TYPE_DEVICE &&
            strcmp((*it).GetCreationInfo(), m_device.GetInfo().GetCreationInfo()) == 0)
        {
            return TRUE;
        }
    }

    return FALSE;
}

XnBool XnSensorDepthGenerator::IsViewPointSupported(xn::ProductionNode& OtherNode)
{
    return IsSensorImageNode(OtherNode);
}

XnStatus XnSensorDepthGenerator::SetViewPoint(xn::ProductionNode& OtherNode)
{
    if (IsSensorImageNode(OtherNode))
    {
        return SetIntProperty(XN_STREAM_PROPERTY_REGISTRATION, TRUE);
    }
    else
    {
        return XN_STATUS_BAD_PARAM;
    }
}

XnStatus XnSensorDepthGenerator::ResetViewPoint()
{
    return SetIntProperty(XN_STREAM_PROPERTY_REGISTRATION, FALSE);
}

XnBool XnSensorDepthGenerator::IsViewPointAs(xn::ProductionNode& OtherNode)
{
    XnUInt64 nValue = FALSE;
    GetIntProperty(XN_STREAM_PROPERTY_REGISTRATION, nValue);

    return (nValue == TRUE && IsSensorImageNode(OtherNode));
}

XnStatus XnSensorDepthGenerator::RegisterToViewPointChange(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
{
    const XnChar* aProps[] = 
    {
        XN_STREAM_PROPERTY_REGISTRATION,
        NULL
    };

    return RegisterToProps(handler, pCookie, hCallback, aProps);
}

void XnSensorDepthGenerator::UnregisterFromViewPointChange(XnCallbackHandle hCallback)
{
    UnregisterFromProps(hCallback);
}

XnBool XnSensorDepthGenerator::CanFrameSyncWith(xn::ProductionNode& OtherNode)
{
    return (IsSensorImageNode(OtherNode));
}

XnStatus XnSensorDepthGenerator::FrameSyncWith(xn::ProductionNode& OtherNode)
{
    if (IsSensorImageNode(OtherNode))
    {
        return m_pSensor->SetProperty(XN_MODULE_NAME_DEVICE, XN_MODULE_PROPERTY_FRAME_SYNC, (XnUInt64)TRUE);
    }
    else
    {
        return XN_STATUS_BAD_PARAM;
    }
}

XnStatus XnSensorDepthGenerator::StopFrameSyncWith(xn::ProductionNode& /*OtherNode*/)
{
    // we assume the other node is the image one (this is the only one we started)
    return m_pSensor->SetProperty(XN_MODULE_NAME_DEVICE, XN_MODULE_PROPERTY_FRAME_SYNC, (XnUInt64)FALSE);
}

XnBool XnSensorDepthGenerator::IsFrameSyncedWith(xn::ProductionNode& OtherNode)
{
    XnUInt64 nValue = FALSE;
    m_pSensor->GetProperty(XN_MODULE_NAME_DEVICE, XN_MODULE_PROPERTY_FRAME_SYNC, &nValue);

    return (nValue == TRUE && IsSensorImageNode(OtherNode));
}

XnStatus XnSensorDepthGenerator::RegisterToFrameSyncChange(XnModuleStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
{
    const XnChar* aProps[] = 
    {
        XN_MODULE_PROPERTY_FRAME_SYNC,
        NULL
    };

    return RegisterToProps(handler, pCookie, hCallback, aProps, XN_MODULE_NAME_DEVICE);
}

void XnSensorDepthGenerator::UnregisterFromFrameSyncChange(XnCallbackHandle hCallback)
{
    UnregisterFromProps(hCallback);
}

void XnSensorDepthGenerator::FilterProperties(XnActualPropertiesHash* pHash)
{
    XnSensorMapGenerator::FilterProperties(pHash);
    pHash->Remove(XN_STREAM_PROPERTY_REGISTRATION);
    pHash->Remove(XN_STREAM_PROPERTY_DEVICE_MAX_DEPTH);
}

//---------------------------------------------------------------------------
// XnExportedSensorDepthGenerator class
//---------------------------------------------------------------------------
XnExportedSensorDepthGenerator::XnExportedSensorDepthGenerator() :
    XnExportedSensorGenerator(XN_NODE_TYPE_DEPTH, XN_STREAM_TYPE_DEPTH)
{}

XnSensorGenerator* XnExportedSensorDepthGenerator::CreateGenerator(xn::Context& context, xn::Device& sensor, XnDeviceBase* pSensor, const XnChar* strStreamName)
{
    return XN_NEW(XnSensorDepthGenerator, context, sensor, pSensor, strStreamName);
}

如果我正确地理解了这个错误,它是说有什么东西试图initialize这个抽象类,这是不允许的。我不是c++开发人员,所以我很好奇如何补救/绕过这个问题来完成编译?

编辑**

我尝试了以下修复方法

  • 将以下虚拟方法添加到/Source/XnDeviceSensorV2/XnSensorDepthGenerator.cppSource/XnDeviceSensorV2/XnSensorGenerator.cpp

虚拟方法:

代码语言:javascript
复制
XnStatus XnSensorDepthGenerator::GetPixelCoordinatesInViewPoint(xn::ProductionNode& other, XnUInt32 x, XnUInt32 y, XnUInt32& altX, XnUInt32& altY)
{
    return 0;
}

在上面的尝试之后,错误没有改变。从那时起,我发现您可以通过预建的二进制文件在mac上安装SensorKinect,所以我尝试了同样的想法,但在Linux上使用了x86二进制文件,但没有成功。

现在我要着手想出一个新的进攻计划。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-13 19:59:46

看起来是个老问题,很久以前就用不同版本的代码库解决了:

https://github.com/avin2/SensorKinect/pull/5

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36601607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档