D435i的C++和python的API调用 windows10

调了一下午的D435i摄像头,主要是想要调用它的API获取信息,搞了一下午,记录一下怎么调试的.....

首先,肯定是先是去GitHub上面找到相关的资源,安装好最主要的SDK

Intel.RealSense.SDK-WIN10-2.49.0.3474.exe

链接在这:

https://github.com/IntelRealSense/librealsense/releases/tag/v2.49.0

翻到最下面就可以看到了!!!

安装好这个SDK,插上D435i就可以看到图像了

我还安装了一个:

Intel.RealSense.Viewer.exe

地址也是上面那个链接,这个要不要取决于自己,非必要的话装不装都无所谓的

上面的步骤完成,基本上就可以从Intel发布的exe上面获取深度信息了,这些都是基操,有手就行

下面的码农该做的,哈哈哈,虽然也知道调用API

首先是python:

第一个肯定是配置环境了!

我的环境是:

python 3.6.14

opencv-python 可以是最新版

numpy 版本好像没有具要求

pyrealsense2 

这些基本上就可以实现很多作者库里面要求的内容了,就这些,搞定了

注意一点的是,我看很多帖子说最好用3.6版本的python,我没有试过其他的,只是建议,用conda搞一个虚拟环境装python3.6也是很方便的,hhhh

最后就是调用这个摄像头的一些基本的例程了:

地址是这个:

https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python

里面的大部分例程,装好上面的环境,插上摄像头就可以跑了

然后是C++:

C++的话肯定也是配环境了,我参考了这个人的方法:

https://blog.csdn.net/leon_zeng0/article/details/103363109

D435i的C++和python的API调用 windows10_第1张图片

这个只是配置一下环境,里面的Intel RealSense SDK 2.0就是第一步装的SDK,找到他的地址就可以了,然后根据上面这个人的方法去配置一下环境就好了 

注:我还遇到一个问题就是,所有步骤搞定之后,报错说找不到realsense2.dll

我的解决方法就是根据装opencv解决这个方法一样的,把SDK2中bin/x64里面的realsense2.dll 放到windows/system32这个路径下面,然后我还把SDK的路径加到了环境变量里面去,具体怎么加看一下opencv的安装方法了咯。

至此,我的vs2019的环境就配置好了

下面的代码是GitHub上面的给出来的例程:

// License: Apache 2.0. See LICENSE file in root directory.
// Copyright(c) 2019 Intel Corporation. All Rights Reserved.

#include  // Include RealSense Cross Platform API
#include              // for cout

// Hello RealSense example demonstrates the basics of connecting to a RealSense device
// and taking advantage of depth data
int main(int argc, char * argv[]) try
{
    // Create a Pipeline - this serves as a top-level API for streaming and processing frames
    rs2::pipeline p;

    // Configure and start the pipeline
    p.start();

    while (true)
    {
        // Block program until frames arrive
        rs2::frameset frames = p.wait_for_frames();

        // Try to get a frame of a depth image
        rs2::depth_frame depth = frames.get_depth_frame();

        // Get the depth frame's dimensions
        auto width = depth.get_width();
        auto height = depth.get_height();

        // Query the distance from the camera to the object in the center of the image
        float dist_to_center = depth.get_distance(width / 2, height / 2);

        // Print the distance
        std::cout << "The camera is facing an object " << dist_to_center << " meters away \r";
    }

    return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{
    std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n    " << e.what() << std::endl;
    return EXIT_FAILURE;
}
catch (const std::exception& e)
{
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
}

 就可以直接跑了。

 

 

你可能感兴趣的:(python,c++,pycharm)