当前位置: 首页>>代码示例>>C++>>正文


C++ Context::EnumerateProductionTrees方法代码示例

本文整理汇总了C++中Context::EnumerateProductionTrees方法的典型用法代码示例。如果您正苦于以下问题:C++ Context::EnumerateProductionTrees方法的具体用法?C++ Context::EnumerateProductionTrees怎么用?C++ Context::EnumerateProductionTrees使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Context的用法示例。


在下文中一共展示了Context::EnumerateProductionTrees方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: openDeviceFromXmlWithChoice

XnStatus openDeviceFromXmlWithChoice(const char* csXmlFile, EnumerationErrors& errors)
{
    XnStatus nRetVal = XN_STATUS_OK;

    xnLogInitFromXmlFile(csXmlFile);

    nRetVal = g_Context.Init();
    XN_IS_STATUS_OK(nRetVal);

    // find devices
    NodeInfoList list;
    nRetVal = g_Context.EnumerateProductionTrees(XN_NODE_TYPE_DEVICE, NULL, list, &errors);
    XN_IS_STATUS_OK(nRetVal);

    printf("The following devices were found:\n");
    int i = 1;
    for (NodeInfoList::Iterator it = list.Begin(); it != list.End(); ++it, ++i)
    {
        NodeInfo deviceNodeInfo = *it;

        Device deviceNode;
        deviceNodeInfo.GetInstance(deviceNode);
        XnBool bExists = deviceNode.IsValid();
        if (!bExists)
        {
            g_Context.CreateProductionTree(deviceNodeInfo, deviceNode);
            // this might fail.
        }

        if (deviceNode.IsValid() && deviceNode.IsCapabilitySupported(XN_CAPABILITY_DEVICE_IDENTIFICATION))
        {
            const XnUInt32 nStringBufferSize = 200;
            XnChar strDeviceName[nStringBufferSize];
            XnChar strSerialNumber[nStringBufferSize];

            XnUInt32 nLength = nStringBufferSize;
            deviceNode.GetIdentificationCap().GetDeviceName(strDeviceName, nLength);
            nLength = nStringBufferSize;
            deviceNode.GetIdentificationCap().GetSerialNumber(strSerialNumber, nLength);
            printf("[%d] %s (%s)\n", i, strDeviceName, strSerialNumber);
        }
        else
        {
            printf("[%d] %s\n", i, deviceNodeInfo.GetCreationInfo());
        }

        // release the device if we created it
        if (!bExists && deviceNode.IsValid())
        {
            deviceNode.Release();
        }
    }
    printf("\n");
    printf("Choose device to open (1): ");

    int chosen = 1;
    scanf("%d", &chosen);

    // create it
    NodeInfoList::Iterator it = list.Begin();
    for (i = 1; i < chosen; ++i)
    {
        it++;
    }

    NodeInfo deviceNode = *it;
    nRetVal = g_Context.CreateProductionTree(deviceNode, g_Device);
    XN_IS_STATUS_OK(nRetVal);

    // now run the rest of the XML
    nRetVal = g_Context.RunXmlScriptFromFile(csXmlFile, g_scriptNode, &errors);
    XN_IS_STATUS_OK(nRetVal);

    openCommon();

    return (XN_STATUS_OK);
}
开发者ID:mpweinge,项目名称:KinectHandTracker,代码行数:77,代码来源:Device.cpp

示例2: enumerateDevices

void enumerateDevices(int initType)
{
    NodeInfoList device_node_info_list;
    NodeInfoList depth_node_info_list;
    NodeInfoList image_node_info_list;
    Context context;
    XnStatus status;

    if (initType == 0)
        status = context.InitFromXmlFile("D:\\initXml.xml");
    else
        status = context.Init();
    // TODO: check errors

    printf("devices:\n");
    
    status = context.EnumerateProductionTrees(XN_NODE_TYPE_DEVICE, NULL, device_node_info_list);
    if (status != XN_STATUS_OK && device_node_info_list.Begin() != device_node_info_list.End())
    {
        printf("Enumerating devices failed. Reason: %s", xnGetStatusString(status));
    }
    for (NodeInfoList::Iterator nodeIt = device_node_info_list.Begin(); nodeIt != device_node_info_list.End(); ++nodeIt)
    {
        const xn::NodeInfo& info = *nodeIt;
        const XnProductionNodeDescription& description = info.GetDescription();
        printf("device: vendor %s name %s, instance %s\n", description.strVendor, description.strName, info.GetInstanceName());
        
        unsigned short vendor_id; 
        unsigned short product_id; 
        unsigned char bus; 
        unsigned char address; 
        sscanf(info.GetCreationInfo(), "%hx/%[email protected]%hhu/%hhu", &vendor_id, &product_id, &bus, &address); 
        string connection_string = info.GetCreationInfo(); 
        transform (connection_string.begin (), connection_string.end (), connection_string.begin (), tolower); 
        printf("vendor_id %i product_id %i bus %i address %i connection %s \n", vendor_id, product_id, bus, address, connection_string.c_str()); 

    }

    //enumerate depth nodes
    printf("depth nodes:\n");
    status = context.EnumerateProductionTrees(XN_NODE_TYPE_DEPTH, NULL, depth_node_info_list, NULL);
    if (status != XN_STATUS_OK)
    {
        printf("enumerating depth generators failed. Reason: %s\n", xnGetStatusString(status));
    }
    else
    {
        for (NodeInfoList::Iterator nodeIt = depth_node_info_list.Begin(); nodeIt != depth_node_info_list.End(); ++ nodeIt)
        {
            const NodeInfo& info = *nodeIt;
            const XnProductionNodeDescription& description = info.GetDescription();
            printf("depth: vendor %s name %s, instance %s\n", description.strVendor, description.strName, info.GetInstanceName());

            unsigned short vendor_id; 
            unsigned short product_id; 
            unsigned char bus; 
            unsigned char address; 
            sscanf(info.GetCreationInfo(), "%hx/%[email protected]%hhu/%hhu", &vendor_id, &product_id, &bus, &address); 
            string connection_string = info.GetCreationInfo(); 
            transform (connection_string.begin (), connection_string.end (), connection_string.begin (), tolower); 
            printf("vendor_id %i product_id %i bus %i address %i connection %s \n", vendor_id, product_id, bus, address, connection_string.c_str()); 
        }
    }

     // enumerate image nodes 
     printf("image nodes:\n"); 
     status = context.EnumerateProductionTrees(XN_NODE_TYPE_IMAGE, NULL, image_node_info_list, NULL); 
     if (status != XN_STATUS_OK) 
     { 
         printf("enumerating image generators failed. Reason: %s\n", xnGetStatusString (status)); 
     } else 
     {
         for (NodeInfoList::Iterator nodeIt = image_node_info_list.Begin(); nodeIt != image_node_info_list.End(); ++nodeIt) 
         { 
             const NodeInfo& info = *nodeIt; 
             const XnProductionNodeDescription& description = info.GetDescription(); 
             printf("image: vendor %s name %s, instance %s\n", description.strVendor, description.strName, info.GetInstanceName()); 
         } 
     } 
}
开发者ID:pechu40,项目名称:HelloKinect,代码行数:80,代码来源:helloKinect.cpp

示例3: OneKinect

void OneKinect(int type)
{
    NodeInfoList image_node_info_list;
    NodeInfoList depth_node_info_list;
    XnStatus status;
    Context context;
    int c;
    IplImage* kinectRGBImage;
    bool bShouldrun = true;

    context.Init();
//	status = context.InitFromXmlFile("D:\\initXml.xml");
    Query query;
    
    switch (type) {

    case 0: 
        status = query.SetVendor("PrimeSense");
        status = context.EnumerateProductionTrees(XN_NODE_TYPE_DEPTH, &query, depth_node_info_list, NULL);
        //status = context.EnumerateProductionTrees(XN_NODE_TYPE_DEPTH, NULL, depth_node_info_list, NULL);
        if (status != XN_STATUS_OK)
            printf("Enumerating devices failed. Reason: %s", xnGetStatusString(status));
        else
        {
            NodeInfoList::Iterator nodeIt = depth_node_info_list.Begin();
//			NodeInfo& selectedNode = *depth_node_info_list.Begin();
//			nodeIt++;
            
            NodeInfo& selectedNode = *nodeIt;

            printf("instance %s\n", selectedNode.GetInstanceName());

            DepthGenerator depth;
            status = selectedNode.GetInstance(depth);
            status = context.CreateProductionTree(selectedNode);
            status = depth.Create(context);
            status = context.StartGeneratingAll();
            cvNamedWindow("Depth", 1);

            // Create an OpenCv matrix
            CvMat* depthMetersMat = cvCreateMat(480, 640, CV_16UC1);
            IplImage *kinectDepthImage;

            while (bShouldrun)
            {
                status = context.WaitOneUpdateAll(depth);
                if (status)
                {
                    printf("Error: %s", xnGetStatusString(status));
                    continue;
                }
                //Take current depth map
                const XnDepthPixel* pDepthMap = depth.GetDepthMap();
                for (int y=0; y<XN_VGA_Y_RES; y++)
                {
                    for (int x=0; x<XN_VGA_X_RES; x++)
                    {
                        depthMetersMat->data.s[y*XN_VGA_X_RES+x]=10*pDepthMap[y*XN_VGA_X_RES+x];
                    }
                }
                kinectDepthImage = cvCreateImage(cvSize(640,480),8,1);
                cvGetImage(depthMetersMat, kinectDepthImage);
                cvShowImage("Depth", kinectDepthImage);
                cvReleaseImageHeader(&kinectDepthImage);
                c = cvWaitKey(1);
                if (c == 27)
                    bShouldrun = false;
            }

        }
        break;
        
    case 1:
        status = context.EnumerateProductionTrees(XN_NODE_TYPE_IMAGE, NULL, image_node_info_list, NULL); 
        if (status != XN_STATUS_OK)
            printf("Enumerating devices failed. Reason: %s", xnGetStatusString(status));
        else
        {
            NodeInfo& selectedNode = *image_node_info_list.Begin();
            xn::ImageGenerator rgb;
            status = selectedNode.GetInstance(rgb);
            status = context.CreateProductionTree(selectedNode);
            status = rgb.Create(context);
            
            status = context.StartGeneratingAll();
            cvNamedWindow("RGB", 1);

            while (bShouldrun)
            {
                kinectRGBImage = cvCreateImage(cvSize(640,480),8,3);
                // Wait for new data to be available
                status = context.WaitOneUpdateAll(rgb);
                if (status != XN_STATUS_OK)
                {
                    printf("Failed updating data: %s\n");
                    xnGetStatusString(status);
                    continue;
                }
                // Take current rgb map
                const XnRGB24Pixel* pImageMap = rgb.GetRGB24ImageMap();
//.........这里部分代码省略.........
开发者ID:pechu40,项目名称:HelloKinect,代码行数:101,代码来源:helloKinect.cpp

示例4: record

int recorder::record()
{
    Recording = true;
    qDebug("//////////////////////////////////////");
    qDebug("/// Welcome to the Kinect Recorder!///");
    qDebug("/// Press any key to STOP recording!//\n");

    bool record_rgb=true;

    //Metadata
    QFileInfo MetadataFile;
    MetadataFile.setFile(QDir::currentPath() + "/Metadata.txt");

    ofstream Metadata_file;

    if(MetadataFile.exists()){
        qDebug("Metadata File exists ");
        Metadata_file.open(MetadataFile.absoluteFilePath().toLocal8Bit(), ofstream::out | ofstream::app);
        Metadata_file.close();
    }
    else{
        qDebug("Metadata File doesn't exist ");
        Metadata_file.open(MetadataFile.absoluteFilePath().toLocal8Bit(), ofstream::out | ofstream::app);
        Metadata_file.close();
    }

    //Status variable
    XnStatus nRetVal = XN_STATUS_OK;

    //Context
    Context context;
    nRetVal = context.Init();

    //Vectors of Generators
    DepthGenerator DepthsGen[MAXGENERATORS];
    ImageGenerator ImagesGen[MAXGENERATORS];
    Recorder Recorders[MAXGENERATORS];

    //Node list.
    NodeInfoList node_info_list;
    NodeInfoList depth_nodes;
    NodeInfoList img_nodes;

    int nKinects = 0;
    int nDepths = 0;
    int nImg = 0;
    int Frames=0;

    //Enumeramos los nodos
    nRetVal = context.EnumerateProductionTrees(XN_NODE_TYPE_DEVICE, NULL,node_info_list);

    //Comprobamos la enumeración
    if(nRetVal != XN_STATUS_OK && node_info_list.Begin() != node_info_list.End()){
        qDebug ("Enumerating devices failed. Reason: %s", xnGetStatusString(nRetVal));
        return -1;
    }

    else if(node_info_list.Begin () == node_info_list.End()){
        qDebug("No devices found.\n");
        return -1;
    }

    for (xn::NodeInfoList::Iterator nodeIt = node_info_list.Begin(); nodeIt != node_info_list.End(); ++nodeIt){
        NodeInfo info = *nodeIt;
        const XnProductionNodeDescription& description = info.GetDescription();
        qDebug("Info: vendor %s name %s , instance %s",description.strVendor,description.strName, info.GetInstanceName());
    }

    //Count number of devices available for recording
    for (NodeInfoList::Iterator nodeIt = node_info_list.Begin(); nodeIt != node_info_list.End(); ++nodeIt){
        nKinects++;
    }
    qDebug("Number of Devices %d", nKinects);

    //Enumerate depth Devices
    nRetVal = context.EnumerateProductionTrees(XN_NODE_TYPE_DEPTH, NULL, depth_nodes, NULL);
    if (nRetVal != XN_STATUS_OK && depth_nodes.Begin () != depth_nodes.End ()) {
        qDebug ("Enumerating devices failed. Reason: %s", xnGetStatusString (nRetVal));
        return -1;
    }
    else if (depth_nodes.Begin () == depth_nodes.End ()) {
        qDebug("No devices found.\n");
        return -1;
    }

    //Enumerate RGB Devices
    if(record_rgb){
        //IMAGE devices
        nRetVal = context.EnumerateProductionTrees(XN_NODE_TYPE_IMAGE, NULL, img_nodes, NULL);
        if (nRetVal != XN_STATUS_OK && img_nodes.Begin () != img_nodes.End ()) {
            qDebug ("Enumerating devices failed. Reason: %s", xnGetStatusString (nRetVal));
            return -1;
        }
        else if (img_nodes.Begin () == img_nodes.End ()) {
            qDebug("No devices found.\n");
            return -1;
        }
    }

    //Show depth devices
//.........这里部分代码省略.........
开发者ID:Sahloul,项目名称:simple-kinect-record-openni,代码行数:101,代码来源:recorder.cpp


注:本文中的Context::EnumerateProductionTrees方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。