depth_camera降低cpu消耗

  上司突然说depth_camera的cpu太高了,其实加入amp filter以后经过调整也没有比以前高,但是人家说高,那就想办法降低呗,毕竟打工人,不过经过这个过程也学到了一些东西。

1.C++程序性能分析

  想降低cpu消耗首先要知道那里消耗的cpu多,好对症下药。这里使用了google的性能分析工具google-perftools.

1)先到github上下载源代码:https://github.com/gperftools/gperftools/releases

(当时用的是2.7版本https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz)

按照说明进行编译,因为我们是rk3399,所以去百度一下怎么在arm上编译

tar -xvf gperftools-2.7.tar.gz  //解压并进入其源码根目录
./autogen.sh
./configure
make && make install  // 相关库和头文件将被安装到 /usr/local 目录下

编译好了以后把生成的库文件、头文件都搞到自己的工程里.具体是下边这些文件:

/usr/local/include/gperftools/                    
/usr/local/lib/lib{profiler, tcmalloc*}.*
/usr/local/lib/pkgconfig/lib{profiler, tcmalloc*}.*

2)在自己的工程里使用google-perftools,有两种方法

第一种

#include<google/profiler.h>

void myfunc()
{
    ProfilerStart("my.prof");
    // things to do
    ProfilerStop();
}

第二种

#include <google/profiler.h>
#include <signal.h>

using namespace std;

static void gprof_callback(int signum)
{
    if(signum == SIGUSR1)
    {
        cout << "Catch signal ProfilerStart\n" << endl;
        ProfilerStart("my.prof");
    }
    else if(signum == SIGUSR2)
    {
        cout << "Catch signal ProfilerStop\n" << endl;
        ProfilerStop();
    }
}

static void setup_signal()
{
    struct sigaction profstat;
    profstat.sa_handler = gprof_callback;
    profstat.sa_flags = 0;
    sigemptyset(&profstat.sa_mask);
    sigaddset(&profstat.sa_mask, SIGUSR1);
    sigaddset(&profstat.sa_mask, SIGUSR2);

    if(sigaction(SIGUSR1, &profstat, NULL) < 0)
        cout << "SIGUSR1! Fail !" << endl;

    if(sigaction(SIGUSR2, &profstat, NULL) < 0)
        cout <<  "SIGUSR2! Fail !" << endl;
}

void myfunc()
{
    setup_signal();
    // things to do
}

在嵌入式设备上运行

kill -s SIGUSR1 $pid   //分析开始

kill -s SIGUSR2 $pid   //结束分析

3).prof 文件转换

sudo apt-get install kcachegrind
pprof --callgrind ./myprogram xxx.prof > xxx.callgrind
kcachegrind xxx.callgrind

参考:介绍一个对陌生程序快速进行性能瓶颈分析的技巧 - 皇家救星 - 博客园

2.程序的优化

经过分析发现是一些opencv的操作比较耗时,一些经验

1)降低分辨率对速度提升很明显

2)cv::Mat的遍历方式也很重要 【OpenCV】访问Mat中每个像素的值(新)_小魏的修行路-CSDN博客_opencv访问像素

3)有的时候自己写遍历可能更快一些

感谢您提出的问题!根据您的描述,您想要使用depthimage_to_laserscan节点将订阅的depth话题重映射为oak-d发布的/stereo/depth,并将订阅的depth_camera_info话题重映射为oak-d发布的/stereo/camera_info。然后,您希望将发布的scan重映射为/oak_scan。此外,您还需要运行静态tf变换,将camera_depth_optical_frame变换到oak-d_frame。 要实现这个功能,您可以按照以下步骤进行操作: 1. 在launch文件或终端,使用remap命令来重映射订阅的depth话题和depth_camera_info话题。例如: ``` <node name="depthimage_to_laserscan" pkg="depthimage_to_laserscan" type="depthimage_to_laserscan" output="screen"> <remap from="depth" to="/oak-d/stereo/depth"/> <remap from="depth_camera_info" to="/oak-d/stereo/camera_info"/> </node> ``` 2. 在同一个launch文件或终端,使用remap命令将发布的scan话题重映射为/oak_scan。例如: ``` <node name="scan_publisher" pkg="depthimage_to_laserscan" type="scan_publisher"> <remap from="scan" to="/oak_scan"/> </node> ``` 3. 运行静态tf变换,将camera_depth_optical_frame变换到oak-d_frame。您可以使用tf_static发布器来完成此操作。具体实现方式取决于您所使用的ROS版本。 请注意,这些步骤是一种可能的实现方法,具体的实现方式可能因您的代码结构和需求而有所不同。请根据您的实际情况进行调整。 希望这可以帮助到您!如果您还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值