返回上级
共14条
跳至  页 
  • 阅读数:224发布于2021-03-18 18:50:44

    只看该作者
    ORBBEC Depth Sensor 教学程序深度视觉信息读取失败 复制本文链接

    图片alt
    教学程序如下:

    /#include “OpenNI.h”
    /#include “opencv2\opencv.hpp”

    using namespace openni;

    int main(int argc, char*argv[])
    {
    //初始化OpenNI
    OpenNI::initialize();

    //打开设备
    Device device;
    device.open(ANY_DEVICE);
    
    //创建深度流
    VideoStream depthStream;
    depthStream.create(device, SENSOR_DEPTH);
    
    //设置深度流模式
    VideoMode depthmode;
    depthmode.setPixelFormat(PIXEL_FORMAT_DEPTH_1_MM);
    depthmode.setResolution(640,480);
    depthmode.setFps(30);
    depthStream.setVideoMode(depthmode);
    
    //打开深度流
    depthStream.start();
    
    //创建彩色流
    VideoStream colorStream;
    colorStream.create(device, SENSOR_COLOR);
    
    //设置彩色流模式
    VideoMode colormode;
    colormode.setPixelFormat(PIXEL_FORMAT_RGB888);
    colormode.setResolution(640, 480);
    colormode.setFps(30);
    colorStream.setVideoMode(colormode);
    
    //打开彩色流
    colorStream.start();
    
    VideoFrameRef frame;
    
    VideoStream** pStreams = new VideoStream*[2]{ &depthStream, &colorStream };
    
    while (true)
    {
        int changedStreamDummy;
    
        //等待一帧
        Status rc = OpenNI::waitForAnyStream(pStreams, 2, &changedStreamDummy, 100);
        if (rc != STATUS_OK)
        {
            continue;
        }
    
        //读取深度帧
        rc = depthStream.readFrame(&frame);
        if (rc == STATUS_OK)
        {
            //获取深度数据
            auto depth = frame.getData();
    
            //获取深度宽高
            auto depthwidth = frame.getWidth();
            auto depthheight = frame.getHeight();
    
            //深度帧的处理和渲染
            cv::Mat rawMat(depthheight, depthwidth, CV_16UC1, (void*)depth);
            cv::Mat depthMat;
            rawMat.convertTo(depthMat, CV_8UC1);
    
            cv::imshow("Depth viewer", depthMat);
        }
    
        //读取彩色帧
        rc = colorStream.readFrame(&frame);
        if (rc == STATUS_OK)
        {
            //获取彩色数据
            auto color = frame.getData();
    
            //获取彩色宽高
            auto colorwidth = frame.getWidth();
            auto colorheight = frame.getHeight();
    
            //彩色帧的处理和渲染
            cv::Mat rawMat(colorheight, colorwidth, CV_8UC3, (void*)color);
            cv::Mat colorMat;
            cv::cvtColor(rawMat, colorMat, cv::COLOR_BGR2RGB);
            cv::imshow("Color viewer", colorMat);
        }
    
        //按esc退出
        int key = cv::waitKey(100);
        if (key == 27)
            break;
    }
    
    delete[] pStreams;
    
    //停止深度流和彩色流
    depthStream.stop();
    colorStream.stop();
    
    //销毁深度流和彩色流
    depthStream.destroy();
    colorStream.destroy();
    
    //关闭设备
    device.close();
    
    //释放openNI资源
    OpenNI::shutdown();
    
    return 0;
    

    }
    运行官方的demo包括手势识别骨架识别都没问题,但是debug时候却无返回值也没有深度视觉信息窗口,很疑惑,请问我的问题出在了哪里

    回复 (0)

    举报
  • 发布于2021-03-18 20:37:01

    只看该作者 显示全部

    请说明此教学程序的出处,以及参考程序的正常返回值。

    回复 (0)

    举报
  • 发布于2021-03-20 10:26:31

    只看该作者 显示全部
    沙无净 发表于 2021-03-18 20:37:01

    请说明此教学程序的出处,以及参考程序的正常返回值。

    就是在这个视频中学的
    https://v.qq.com/x/page/p31177d6hau.html
    图片alt
    运行效果如图所示,始终无法读取数据,但是运行公司的.exe是好用的

    回复 (1)

    举报
  • 发布于2021-03-20 16:18:17

    只看该作者 显示全部
    186****7237 发表于 2021-03-20 10:26:31

    就是在这个视频中学的
    https://v.qq.com/x/page/p31177d6hau.html
    图片alt
    运行效果如图所示,始终无法读取数据,但是运行公司的.exe是好用的

    能否告知一下目前您手上使用的相机型号?

    回复 (0)

    举报
  • 发布于2021-03-20 17:17:04

    只看该作者 显示全部
    不爱唠叨的唐僧 发表于 2021-03-20 16:18:17

    能否告知一下目前您手上使用的相机型号?

    LeTMC-520
    乐视三合一体感摄像头

    回复 (0)

    举报
  • 发布于2021-03-22 09:50:18

    只看该作者 显示全部
    186****7237 发表于 2021-03-20 17:17:04

    LeTMC-520
    乐视三合一体感摄像头

    /*****************************************************************************
    *                                                                            *
    *  OpenNI 2.x Alpha                                                          *
    *  Copyright (C) 2012 PrimeSense Ltd.                                        *
    *                                                                            *
    *  This file is part of OpenNI.                                              *
    *                                                                            *
    *  Licensed under the Apache License, Version 2.0 (the "License");           *
    *  you may not use this file except in compliance with the License.          *
    *  You may obtain a copy of the License at                                   *
    *                                                                            *
    *      http://www.apache.org/licenses/LICENSE-2.0                            *
    *                                                                            *
    *  Unless required by applicable law or agreed to in writing, software       *
    *  distributed under the License is distributed on an "AS IS" BASIS,         *
    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
    *  See the License for the specific language governing permissions and       *
    *  limitations under the License.                                            *
    *                                                                            *
    *****************************************************************************/
    #include <OpenNI.h>
    #include "Viewer.h"
    #include "ColorViewer.h"
    
    
    
    int main(int argc, char** argv)
    {
        openni::Status rc = openni::STATUS_OK;
        openni::Device device;
        openni::VideoStream depth, ir;
        openni::VideoStream openNIColor;
        ColorCamera uvcCamera;
    
        const char* deviceURI = openni::ANY_DEVICE;
        if (argc > 1)
        {
            deviceURI = argv[1];
        }
    
        rc = openni::OpenNI::initialize();
    
        printf("After initialization:\n%s\n", openni::OpenNI::getExtendedError());
    
        rc = device.open(deviceURI);
        if (rc != openni::STATUS_OK)
        {
            printf("SimpleViewer: Device open failed:\n%s\n", openni::OpenNI::getExtendedError());
            openni::OpenNI::shutdown();
            return 1;
        }
    
        bool isUvcDevice = true;
        //open uvc stream
        int resolutionX = 640;
        int resolutionY = 480;
        int ret = uvcCamera.UvcInit(resolutionX, resolutionY);
        if (ret != 0)
        {
            isUvcDevice = false;
            printf("SimpleViewer: UvcInit failed.\n");
        }
    
        if (isUvcDevice){
            // if it is uvc device. It can support 3 streams at the same time. 
            rc = ir.create(device, openni::SENSOR_IR);
            if (rc == openni::STATUS_OK)
            {
                openni::VideoMode viewMode = ir.getVideoMode();
                viewMode.setPixelFormat(openni::PIXEL_FORMAT_RGB888);
                ir.setVideoMode(viewMode);
                rc = ir.start();
                if (rc != openni::STATUS_OK)
                {
                    printf("SimpleViewer: Couldn't start ir stream:\n%s\n", openni::OpenNI::getExtendedError());
                    ir.destroy();
                }
            }
            else
            {
                printf("SimpleViewer: Couldn't find ir stream:\n%s\n", openni::OpenNI::getExtendedError());
            }
        }
    
        bool hasOpenNIColor = device.hasSensor(openni::SENSOR_COLOR);
        uint16_t nPid = device.getDeviceInfo().getUsbProductId();
        //astra pro
        if (nPid == 0x0403)
        {
            hasOpenNIColor = false;
        }
    
        if (hasOpenNIColor && !isUvcDevice)
        {
            rc = openNIColor.create(device, openni::SENSOR_COLOR);
            if (rc == openni::STATUS_OK)
            {
    
                openni::VideoMode viewMode = openNIColor.getVideoMode();
                viewMode.setPixelFormat(openni::PIXEL_FORMAT_RGB888);
                openNIColor.setVideoMode(viewMode);
                rc = openNIColor.start();
                if (rc != openni::STATUS_OK)
                {
                    printf("SimpleViewer: Couldn't start color stream:\n%s\n", openni::OpenNI::getExtendedError());
                    openNIColor.destroy();
                }
            }
        }
    
        rc = depth.create(device, openni::SENSOR_DEPTH);
        if (rc == openni::STATUS_OK)
        {
            depth.setMirroringEnabled(false);
            device.setImageRegistrationMode(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR);
            rc = depth.start();
            if (rc != openni::STATUS_OK)
            {
                printf("SimpleViewer: Couldn't start depth stream:\n%s\n", openni::OpenNI::getExtendedError());
                depth.destroy();
            }
        }
        else
        {
            printf("SimpleViewer: Couldn't find depth stream:\n%s\n", openni::OpenNI::getExtendedError());
        }
    
        if (!depth.isValid())
        {
            printf("SimpleViewer: No valid depth streams. Exiting\n");
            openni::OpenNI::shutdown();
            return 2;
        }
    
        ColorViewer sampleViewer("Simple Viewer", &uvcCamera, device, depth, ir, openNIColor, !isUvcDevice);
    
        sampleViewer.init(argc, argv);
        sampleViewer.run();
    }
    

    回复 (0)

    举报
  • 发布于2021-03-22 09:57:26

    只看该作者 显示全部
    186****7237 发表于 2021-03-20 17:17:04

    LeTMC-520
    乐视三合一体感摄像头

    您可以参看一下这段UVC Demo。

    回复 (0)

    举报
  • 发布于2021-03-23 22:12:33

    只看该作者 显示全部
    童虎 发表于 2021-03-22 09:57:26

    您可以参看一下这段UVC Demo。

    include “ColorViewer.h”

    没有这个.h可以发一下吗,谢谢

    回复 (0)

    举报
  • 发布于2021-03-23 22:12:34

    只看该作者 显示全部
    童虎 发表于 2021-03-22 09:57:26

    您可以参看一下这段UVC Demo。

    include “ColorViewer.h”

    没有这个.h可以发一下吗,谢谢

    回复 (0)

    举报
  • 发布于2021-03-24 19:07:46

    只看该作者 显示全部
    /*****************************************************************************
    *                                                                            *
    *  OpenNI 2.x Alpha                                                          *
    *  Copyright (C) 2012 PrimeSense Ltd.                                        *
    *                                                                            *
    *  This file is part of OpenNI.                                              *
    *                                                                            *
    *  Licensed under the Apache License, Version 2.0 (the "License");           *
    *  you may not use this file except in compliance with the License.          *
    *  You may obtain a copy of the License at                                   *
    *                                                                            *
    *      http://www.apache.org/licenses/LICENSE-2.0                            *
    *                                                                            *
    *  Unless required by applicable law or agreed to in writing, software       *
    *  distributed under the License is distributed on an "AS IS" BASIS,         *
    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
    *  See the License for the specific language governing permissions and       *
    *  limitations under the License.                                            *
    *                                                                            *
    *****************************************************************************/
    #ifndef COLOR_VIEWER_H
    #define COLOR_VIEWER_H
    
    #include 
    
    #if (ONI_PLATFORM == ONI_PLATFORM_WIN32)
    #include "colorcamera.h"
    #endif
    
    #define MAX_DEPTH 10000
    //#include "Viewer.h"
    
    class ColorViewer
    {
    public:
        ColorViewer(const char* strSampleName, ColorCamera* colorCamera, openni::Device& device, openni::VideoStream& depth, openni::VideoStream& ir, openni::VideoStream& openniColor, bool hasOpenNIColor);
        virtual ~ColorViewer();
    
        virtual openni::Status init(int argc, char **argv);
        virtual openni::Status run();    //Does not return
    
    protected:
        virtual void display();
        virtual void displayPostDraw(){};    // Overload to draw over the screen image
    
        virtual openni::Status initOpenGL(int argc, char **argv);
        void initOpenGLHooks();
        void ColorViewer::onKey(unsigned char key, int /*x*/, int /*y*/);
    
        bool isUvCCamera;
    
        ColorCamera* m_pColorCamera;
    
        openni::VideoFrameRef        m_depthFrame;
        openni::VideoFrameRef        m_irFrame;
    
        openni::Device&            m_device;
        openni::VideoStream&            m_depthStream;
        openni::VideoStream&            m_irStream;
        openni::VideoStream&            m_openniColorStream;
        openni::VideoStream**        m_streams;
    
    private:
        ColorViewer(const ColorViewer&);
        ColorViewer& operator=(ColorViewer&);
    
        static ColorViewer* ms_self;
        static void glutIdle();
        static void glutDisplay();
        static void glutDisplayOpenNI();
        static void glutKeyboard(unsigned char key, int x, int y);
    
        void prepareUVCColor();
        void prepareDepth();
        void prepareOpenNI();
        void prepareIR();
        void uvcDisplay();
        void openniDisplay();
    
        float            m_pDepthHist[MAX_DEPTH];
        char            m_strSampleName[ONI_MAX_STR];
        unsigned int        m_nTexMapX;
        unsigned int        m_nTexMapY;
        openni::RGB888Pixel*    m_pTexMapColor;
        openni::RGB888Pixel*    m_pTexMapDepth;
        openni::RGB888Pixel*    m_pTexMapIR;
        int            m_width;
        int            m_height;
    };
    #endif // COLOR_VIEWER_H
    

    回复 (0)

    举报
  • 发布于2021-03-26 10:59:44

    只看该作者 显示全部
    沙无净 发表于 2021-03-24 19:07:46

    /*****************************************************************************
    *                                                                            *
    *  OpenNI 2.x Alpha                                                          *
    *  Copyright (C) 2012 PrimeSense Ltd.                                        *
    *                                                                            *
    *  This file is part of OpenNI.                                              *
    *                                                                            *
    *  Licensed under the Apache License, Version 2.0 (the "License");           *
    *  you may not use this file except in compliance with the License.          *
    *  You may obtain a copy of the License at                                   *
    *                                                                            *
    *      http://www.apache.org/licenses/LICENSE-2.0                            *
    *                                                                            *
    *  Unless required by applicable law or agreed to in writing, software       *
    *  distributed under the License is distributed on an "AS IS" BASIS,         *
    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  *
    *  See the License for the specific language governing permissions and       *
    *  limitations under the License.                                            *
    *                                                                            *
    *****************************************************************************/
    #ifndef COLOR_VIEWER_H
    #define COLOR_VIEWER_H
    
    #include 
    
    #if (ONI_PLATFORM == ONI_PLATFORM_WIN32)
    #include "colorcamera.h"
    #endif
    
    #define MAX_DEPTH 10000
    //#include "Viewer.h"
    
    class ColorViewer
    {
    public:
        ColorViewer(const char* strSampleName, ColorCamera* colorCamera, openni::Device& device, openni::VideoStream& depth, openni::VideoStream& ir, openni::VideoStream& openniColor, bool hasOpenNIColor);
        virtual ~ColorViewer();
    
        virtual openni::Status init(int argc, char **argv);
        virtual openni::Status run();    //Does not return
    
    protected:
        virtual void display();
        virtual void displayPostDraw(){};    // Overload to draw over the screen image
    
        virtual openni::Status initOpenGL(int argc, char **argv);
        void initOpenGLHooks();
        void ColorViewer::onKey(unsigned char key, int /*x*/, int /*y*/);
    
        bool isUvCCamera;
    
        ColorCamera* m_pColorCamera;
    
        openni::VideoFrameRef        m_depthFrame;
        openni::VideoFrameRef        m_irFrame;
    
        openni::Device&            m_device;
        openni::VideoStream&            m_depthStream;
        openni::VideoStream&            m_irStream;
        openni::VideoStream&            m_openniColorStream;
        openni::VideoStream**        m_streams;
    
    private:
        ColorViewer(const ColorViewer&);
        ColorViewer& operator=(ColorViewer&);
    
        static ColorViewer* ms_self;
        static void glutIdle();
        static void glutDisplay();
        static void glutDisplayOpenNI();
        static void glutKeyboard(unsigned char key, int x, int y);
    
        void prepareUVCColor();
        void prepareDepth();
        void prepareOpenNI();
        void prepareIR();
        void uvcDisplay();
        void openniDisplay();
    
        float            m_pDepthHist[MAX_DEPTH];
        char            m_strSampleName[ONI_MAX_STR];
        unsigned int        m_nTexMapX;
        unsigned int        m_nTexMapY;
        openni::RGB888Pixel*    m_pTexMapColor;
        openni::RGB888Pixel*    m_pTexMapDepth;
        openni::RGB888Pixel*    m_pTexMapIR;
        int            m_width;
        int            m_height;
    };
    #endif // COLOR_VIEWER_H
    

    公司用的是公司官网的openni2 sdk吗,为什么我连这个#include “colorcamera.h”文件也没有啊,我在openni2的官网下的sdk也没有这个文件:sob:
    求教

    回复 (0)

    举报
返回上级
共14条
跳至  页 
举报

请选择举报理由

  • 垃圾广告
  • 违规内容
  • 恶意灌水
  • 重复发帖
提示

奥比中光 · 3D视觉开发者社区...

站长统计