pcl 安装在docker 镜像中

文章目录

  • 需求
  • 准备

需求

算法服务需要用到pcl 点云库,为了使算法服务横向扩展更方便,所以选择用docker封装算法服务,那么就需要算法的镜像中有pcl类库。

准备

安装环境
在dockerfile中添加如下代码

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src

RUN dotnet restore
COPY . .
 
FROM base AS debuge
WORKDIR /app
# 将cmake离线安装包拷贝到镜像
Add "bin/publish/net5.0/cmake/cmake-3.20.2-linux-x86_64.tar.gz" "/usr/cmake" 
# 更新源
RUN apt-get update
# 安装make和相关依赖
RUN apt-get -y install gcc automake autoconf libtool make
# 安装pcl
RUN apt-get -y install libpcl-dev 
# 创建cmake的连接  ln
RUN ["/bin/bash","-c","ln -s /usr/cmake/cmake-3.20.2-linux-x86_64/bin/* /usr/bin/"]
RUN 
COPY "bin/publish/net5.0/" "/app" 
EXPOSE 80
EXPOSE 443
VOLUME ["/app/datas","/app/logs","/app/conf"]
ENTRYPOINT ["dotnet", "Shimada.CarlingService.dll", "Shimada.CarlingService.Web.dll"]

测试pcl代码

#include 
#include 
#include 
#include 
#include 
#include 


int main(int argc, char** argv) {
    std::cout << "Test PCL !!!" << std::endl;

    pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr(new pcl::PointCloud<pcl::PointXYZRGB>);
    uint8_t r(255), g(15), b(15);
    for (float z(-1.0); z <= 1.0; z += 0.05)
    {
        for (float angle(0.0); angle <= 360.0; angle += 5.0)
        {
            pcl::PointXYZRGB point;
            point.x = 0.5 * cosf(pcl::deg2rad(angle));
            point.y = sinf(pcl::deg2rad(angle));
            point.z = z;
            uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
                static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
            point.rgb = *reinterpret_cast<float*>(&rgb);
            point_cloud_ptr->points.push_back(point);
        }
        if (z < 0.0)
        {
            r -= 12;
            g += 12;
        }
        else
        {
            g -= 12;
            b += 12;
        }
    }
    point_cloud_ptr->width = (int)point_cloud_ptr->points.size();
    point_cloud_ptr->height = 1;
    std::cout << "OKOK !!!" << std::endl;
    // 因为是在docker环境中,所以不用viewer了
   /* pcl::visualization::CloudViewer viewer("test");
    viewer.showCloud(point_cloud_ptr);
    while (!viewer.wasStopped()) {};*/
    return 0;
}

make文件

cmake_minimum_required(VERSION 2.6)
project(pcl_test)
 
find_package(PCL 1.2 REQUIRED)
 
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
 
add_executable(pcl_test pcl_test.cpp)
 
target_link_libraries (pcl_test ${PCL_LIBRARIES})
 
install(TARGETS pcl_test RUNTIME DESTINATION bin)

以上都是做镜像的必要素材

然后制作镜像 docker build 命令

进入镜像后通过下面命令进行测试

mkdir build
cd build
cmake ..
make
./pcl_test

效果如下


详细操作请参考下列文章

https://blog.csdn.net/qq_36728314/article/details/89487719
https://blog.csdn.net/qq_41795143/article/details/111421008
https://pointclouds.org/downloads/#linux

你可能感兴趣的:(分布式,pcl,docker)