Browse Source

change view_pcdmap2, add bin load.

yuchuli 1 month ago
parent
commit
fc96fcbc5f

+ 3 - 0
src/detection/detection_lidar_centerpoint/detection_lidar_centerpoint.pro

@@ -200,3 +200,6 @@ unix:LIBS +=  -lpcl_common\
         -lpcl_tracking\
         -lpcl_visualization
 
+
+LIBS += -lOpen3D
+

+ 47 - 0
src/detection/detection_lidar_centerpoint/main.cpp

@@ -219,6 +219,52 @@ void testdet(std::string & path)
     }
 }
 
+#include <QFile>
+#include <open3d/Open3D.h>
+#include <open3d/core/TensorFunction.h>
+
+#include <open3d/visualization/visualizer/RenderOption.h>
+void testbin()
+{
+    pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
+                new pcl::PointCloud<pcl::PointXYZI>());
+
+    QFile xFile;
+    xFile.setFileName("/home/nvidia/1.bin");
+    if(xFile.open(QIODevice::ReadOnly))
+    {
+        while(1)
+        {
+            float x,y,z,intensity;
+            int nread;
+            xFile.read((char *)&x,sizeof(float));
+            xFile.read((char *)&y,sizeof(float));
+            xFile.read((char *)&z,sizeof(float));
+            nread = xFile.read((char *)&intensity,sizeof(float));
+            if(nread < 4)
+            {
+                break;
+            }
+            pcl::PointXYZI point;
+            point.x = x;
+            point.y = y;
+            point.z = z;
+            point.intensity =  intensity;
+            point_cloud->points.push_back(point);
+            ++point_cloud->width;
+        }
+        xFile.close();
+
+        std::vector<Box3D> det_boxes3d;
+        int i;
+        for(i=0;i<10;i++)
+        {
+        detector_ptr_ ->detect(point_cloud,det_boxes3d);
+        std::cout<<" box size: "<<det_boxes3d.size()<<std::endl;
+        }
+    }
+}
+
 
 int main(int argc, char *argv[])
 {
@@ -226,6 +272,7 @@ int main(int argc, char *argv[])
     init();
 
     std::string path = "/home/nvidia/1.pcd";
+//    testbin();
 //    testdet(path);
 
     gpa = iv::modulecomm::RegisterRecv("lidar_pc",ListenPointCloud);

+ 18 - 3
src/tool/pointcloudviewer_open3d/main.cpp

@@ -10,6 +10,8 @@
 #include <pcl/io/pcd_io.h>
 #include <pcl/common/io.h>
 
+#include <thread>
+
 #include <QFile>
 
 bool readpcd(std::string strpcdpath,open3d::t::geometry::PointCloud &cloud)
@@ -73,18 +75,31 @@ void test()
         vis.AddGeometry(std::make_shared<open3d::geometry::PointCloud>(
             cloud_ptr->ToLegacy().PaintUniformColor({1.0, 1.0, 1.0})));
 
-        vis.AddGeometry(std::make_shared<open3d::geometry::PointCloud>(
-            cloud_ptr->ToLegacy().PaintUniformColor({1.0, 1.0, 1.0})));
 
         vis.Run();
         vis.DestroyVisualizerWindow();
     }
 }
 
+
+void threadvis()
+{
+    test();
+    std::cout<<" vis close."<<std::endl;
+}
+
+
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
 
-    test();
+    std::thread * pt = new std::thread(&threadvis);
+
+    while(1)
+    {
+        std::this_thread::sleep_for(std::chrono::seconds(1));
+        std::cout<<"main."<<std::endl;
+    }
+//    test();
     return a.exec();
 }

+ 49 - 2
src/tool/view_pcdmap/mainwindow.cpp

@@ -4,6 +4,8 @@
 #include <iostream>
 
 #include <QFileDialog>
+#include <QMessageBox>
+#include <QFile>
 
 
 MainWindow::MainWindow(QWidget *parent)
@@ -52,9 +54,54 @@ void MainWindow::on_actionLoad_triggered()
 {
     //读取pcd文件并显示
     pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>());//创建点云指针
-    QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open PCD files(*.pcd)");
+    QString fileName = QFileDialog::getOpenFileName(this, "Open PointCloud", ".", "Open files(*.*)");
     if(fileName == "") return;
-    pcl::io::loadPCDFile(fileName.toStdString(),*cloud);
+    if((fileName.right(4) != ".pcd") &&(fileName.right(4) != ".bin"))
+    {
+        QMessageBox::warning(this,tr("Warning"),tr("Not .pcd or .bin file."),QMessageBox::YesAll);
+        return;
+    }
+    if(fileName.right(4) == ".pcd")
+    {
+        pcl::io::loadPCDFile(fileName.toStdString(),*cloud);
+    }
+    if(fileName.right(4) == ".bin")
+    {
+        QFile xFile;
+        xFile.setFileName(fileName);
+        if(xFile.open(QIODevice::ReadOnly))
+        {
+
+            while(1)
+            {
+
+                float x,y,z,intensity;
+                int nread;
+                xFile.read((char *)&x,sizeof(float));
+                xFile.read((char *)&y,sizeof(float));
+                xFile.read((char *)&z,sizeof(float));
+                nread = xFile.read((char *)&intensity,sizeof(float));
+                if(nread < 4)
+                {
+                    break;
+                }
+                pcl::PointXYZI point;
+                point.x = x;
+                point.y = y;
+                point.z = z;
+                point.intensity =  intensity;
+                cloud->points.push_back(point);
+                ++cloud->width;
+            }
+        }
+        else
+        {
+            QMessageBox::warning(this,tr("Warning"),tr("Can't Read File."),QMessageBox::YesAll);
+            return;
+        }
+        xFile.close();
+
+    }
     pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZI> fildColor(cloud, "intensity"); // 按照y字段进行渲染
     view->removePointCloud("cloud");
     view->addPointCloud<pcl::PointXYZI>(cloud,fildColor,"cloud");