Răsfoiți Sursa

add pcd2bin.

yuchuli 3 luni în urmă
părinte
comite
76231ff227
3 a modificat fișierele cu 269 adăugiri și 0 ștergeri
  1. 73 0
      src/tool/pcd2bin/.gitignore
  2. 154 0
      src/tool/pcd2bin/main.cpp
  3. 42 0
      src/tool/pcd2bin/pcd2bin.pro

+ 73 - 0
src/tool/pcd2bin/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 154 - 0
src/tool/pcd2bin/main.cpp

@@ -0,0 +1,154 @@
+#include <QCoreApplication>
+
+#include <iostream>
+//#include <pcl/io/io.h>
+#include <pcl/io/pcd_io.h>
+#include <pcl/common/io.h>
+
+#include <QFile>
+
+#include <getopt.h>
+
+
+static char gstrpcdpath[256];
+static char gstrbinpath[256];
+
+void print_useage()
+{
+    std::cout<<" -i --input $pcdpath : map path. eq.  -i /home/nvidia/input.pcd"<<std::endl;
+    std::cout<<" -o --output $binpath : bin path. eq.  -o /home/nvidia/output.bin"<<std::endl;
+    std::cout<<" -h --help print help"<<std::endl;
+}
+
+int  GetOptLong(int argc, char *argv[]) {
+    int nRtn = 0;
+    int opt; // getopt_long() 的返回值
+    int digit_optind = 0; // 设置短参数类型及是否需要参数
+
+
+    // 如果option_index非空,它指向的变量将记录当前找到参数符合long_opts里的
+    // 第几个元素的描述,即是long_opts的下标值
+    int option_index = 0;
+    // 设置短参数类型及是否需要参数
+    const char *optstring = "i:o:h";
+
+    // 设置长参数类型及其简写,比如 --reqarg <==>-r
+    /*
+    struct option {
+             const char * name;  // 参数的名称
+             int has_arg; // 是否带参数值,有三种:no_argument, required_argument,optional_argument
+             int * flag; // 为空时,函数直接将 val 的数值从getopt_long的返回值返回出去,
+                     // 当非空时,val的值会被赋到 flag 指向的整型数中,而函数返回值为0
+             int val; // 用于指定函数找到该选项时的返回值,或者当flag非空时指定flag指向的数据的值
+        };
+    其中:
+        no_argument(即0),表明这个长参数不带参数(即不带数值,如:--name)
+            required_argument(即1),表明这个长参数必须带参数(即必须带数值,如:--name Bob)
+            optional_argument(即2),表明这个长参数后面带的参数是可选的,(即--name和--name Bob均可)
+     */
+    static struct option long_options[] = {
+        {"input", required_argument, NULL, 'i'},
+        {"output", required_argument, NULL, 'o'},
+        {"help",  no_argument,       NULL, 'h'},
+ //       {"optarg", optional_argument, NULL, 'o'},
+        {0, 0, 0, 0}  // 添加 {0, 0, 0, 0} 是为了防止输入空值
+    };
+
+    while ( (opt = getopt_long(argc,
+                               argv,
+                               optstring,
+                               long_options,
+                               &option_index)) != -1) {
+//        printf("opt = %c\n", opt); // 命令参数,亦即 -a -b -n -r
+//        printf("optarg = %s\n", optarg); // 参数内容
+//        printf("optind = %d\n", optind); // 下一个被处理的下标值
+//        printf("argv[optind - 1] = %s\n",  argv[optind - 1]); // 参数内容
+//        printf("option_index = %d\n", option_index);  // 当前打印参数的下标值
+//        printf("\n");
+        switch(opt)
+        {
+        case 'i':
+            strncpy(gstrpcdpath,optarg,255);
+            break;
+        case 'o':
+            strncpy(gstrbinpath,optarg,255);
+            break;
+        case 'h':
+            print_useage();
+            nRtn = 1; //because use -h
+            break;
+        default:
+            break;
+        }
+
+    }
+
+    return nRtn;
+}
+
+
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    snprintf(gstrpcdpath,255,"");
+    snprintf(gstrbinpath,255,"");
+
+    int nRtn = GetOptLong(argc,argv);
+    if(nRtn == 1)  //show help,so exit.
+    {
+        return 0;
+    }
+
+    if(strnlen(gstrpcdpath,256) < 1)
+    {
+        std::cout<<" no input."<<std::endl;
+        print_useage();
+        return -1;
+    }
+
+    if(strnlen(gstrbinpath,256) < 1)
+    {
+        std::cout<<" no output."<<std::endl;
+        print_useage();
+        return -2;
+    }
+
+    pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
+                new pcl::PointCloud<pcl::PointXYZI>());
+
+    pcl::io::loadPCDFile<pcl::PointXYZI>(gstrpcdpath,*point_cloud);
+
+
+    QFile xFile;
+    xFile.setFileName(gstrbinpath);
+    if(!xFile.open(QIODevice::ReadWrite))
+    {
+        std::cout<<" Open Save bin File Fail."<<std::endl;
+        return -3;
+    }
+
+    int i;
+    int nPCount = static_cast<int>(point_cloud->width);
+    for(i=0;i<nPCount;i++)
+    {
+        pcl::PointXYZI xp = point_cloud->points[i];
+        double x,y,z,intesi;
+        x = xp.x;
+        y = xp.y;
+        z = xp.z;
+        intesi = xp.intensity;
+        xFile.write((char *)&x,sizeof(double));
+        xFile.write((char *)&y,sizeof(double));
+        xFile.write((char *)&z,sizeof(double));
+        xFile.write((char *)&intesi,sizeof(double));
+
+    }
+    xFile.close();
+    return 0;
+
+
+
+//    return a.exec();
+}

+ 42 - 0
src/tool/pcd2bin/pcd2bin.pro

@@ -0,0 +1,42 @@
+QT -= gui
+
+CONFIG += c++1z console
+CONFIG -= app_bundle
+
+# You can make your code fail to compile if it uses deprecated APIs.
+# In order to do so, uncomment the following line.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += \
+        main.cpp
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
+
+!include(../../../include/ivpcl.pri ) {
+    error( "Couldn't find the ivpcl.pri file!" )
+}
+
+
+LIBS += -lboost_system -lboost_program_options
+
+unix:LIBS +=  -lpcl_common\
+        -lpcl_features\
+        -lpcl_filters\
+        -lpcl_io\
+        -lpcl_io_ply\
+        -lpcl_kdtree\
+        -lpcl_keypoints\
+        -lpcl_octree\
+        -lpcl_outofcore\
+        -lpcl_people\
+        -lpcl_recognition\
+        -lpcl_registration\
+        -lpcl_sample_consensus\
+        -lpcl_search\
+        -lpcl_segmentation\
+        -lpcl_surface\
+        -lpcl_tracking\
+        -lpcl_visualization