|
@@ -1,8 +1,143 @@
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
+#include <QDateTime>
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+#include "pointpillars.h"
|
|
|
+
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
+#include <pcl/point_cloud.h>
|
|
|
+#include <pcl/point_types.h>
|
|
|
+#include <pcl/io/io.h>
|
|
|
+#include <pcl/io/pcd_io.h>
|
|
|
+
|
|
|
+void PclToArray(
|
|
|
+ const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
|
|
|
+ float* out_points_array, const float normalizing_factor) {
|
|
|
+ for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
|
|
|
+ pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
|
|
|
+ out_points_array[i * 3 + 0] = point.x;
|
|
|
+ out_points_array[i * 3 + 1] = point.y;
|
|
|
+ out_points_array[i * 3 + 2] = point.z;
|
|
|
+ out_points_array[i * 4 + 3] =
|
|
|
+ static_cast<float>(point.intensity / normalizing_factor);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void PclXYZITToArray(
|
|
|
+ const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
|
|
|
+ float* out_points_array, const float normalizing_factor) {
|
|
|
+ for (size_t i = 0; i < in_pcl_pc_ptr->size(); ++i) {
|
|
|
+ pcl::PointXYZI point = in_pcl_pc_ptr->at(i);
|
|
|
+ out_points_array[i * 5 + 0] = point.x;
|
|
|
+ out_points_array[i * 5 + 1] = point.y;
|
|
|
+ out_points_array[i * 5 + 2] = point.z;
|
|
|
+ out_points_array[i * 5 + 3] =
|
|
|
+ static_cast<float>(point.intensity / normalizing_factor);
|
|
|
+ out_points_array[i * 5 + 4] = 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void Boxes2Txt( std::vector<float> boxes , string file_name , int num_feature = 7)
|
|
|
+{
|
|
|
+ ofstream ofFile;
|
|
|
+ ofFile.open(file_name , std::ios::out );
|
|
|
+ if (ofFile.is_open()) {
|
|
|
+ for (int i = 0 ; i < boxes.size() / num_feature ; ++i) {
|
|
|
+ for (int j = 0 ; j < num_feature ; ++j) {
|
|
|
+ ofFile << boxes.at(i * num_feature + j) << " ";
|
|
|
+ }
|
|
|
+ ofFile << "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ofFile.close();
|
|
|
+ return ;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+void test(std::string pfe_file,std::string backbone_file,std::string pp_config)
|
|
|
+{
|
|
|
+
|
|
|
+ PointPillars * pPillars;
|
|
|
+ pPillars = new PointPillars(
|
|
|
+ 0.1,
|
|
|
+ 0.2,
|
|
|
+ true,
|
|
|
+ pfe_file,
|
|
|
+ backbone_file,
|
|
|
+ pp_config
|
|
|
+ );
|
|
|
+ std::cout<<"PointPillars Init OK."<<std::endl;
|
|
|
+
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr xpc(
|
|
|
+ new pcl::PointCloud<pcl::PointXYZI>);
|
|
|
+
|
|
|
+
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr xpcfile;
|
|
|
+
|
|
|
+ xpcfile = boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI>>(new pcl::PointCloud<pcl::PointXYZI>);
|
|
|
+
|
|
|
+ if(0 == pcl::io::loadPCDFile("/home/nvidia/20200604054241688.pcd",*xpc))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<"load pcd fail"<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const int kNumPointFeature = 5;
|
|
|
+ const int kOutputNumBoxFeature = 7;
|
|
|
+
|
|
|
+
|
|
|
+// for (size_t i = 0; i < xpcfile->size(); ++i) {
|
|
|
+// pcl::PointXYZI point;
|
|
|
+// point.x = xpcfile->at(i).x;
|
|
|
+// point.y = xpcfile->at(i).y;qt
|
|
|
+// point.z = xpcfile->at(i).z;
|
|
|
+// point.intensity = 0;
|
|
|
+// xpc->push_back(point);
|
|
|
+// }
|
|
|
+
|
|
|
+ std::cout<<"point size is "<<xpc->width<<std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ float* points_array = new float[xpc->size() * kNumPointFeature];
|
|
|
+ PclXYZITToArray(xpc, points_array, 255.0);
|
|
|
+
|
|
|
+ int in_num_points = in_num_points;
|
|
|
+
|
|
|
+ std::vector<float> out_detections;
|
|
|
+ std::vector<int> out_labels;
|
|
|
+ std::vector<float> out_scores;
|
|
|
+
|
|
|
+ QTime xTime;
|
|
|
+
|
|
|
+ xTime.start();
|
|
|
+
|
|
|
+ cudaDeviceSynchronize();
|
|
|
+ pPillars->DoInference(points_array, in_num_points, &out_detections, &out_labels , &out_scores);
|
|
|
+ cudaDeviceSynchronize();
|
|
|
+ int BoxFeature = 7;
|
|
|
+ int num_objects = out_detections.size() / BoxFeature;
|
|
|
+
|
|
|
+ std::cout<<"objects num: "<<num_objects<<std::endl;
|
|
|
+ std::cout<<"infer time: "<<xTime.elapsed()<<std::endl;
|
|
|
+
|
|
|
+ std::string boxes_file_name = "/home/nvidia/pointpillarsout.txt";
|
|
|
+ Boxes2Txt(out_detections , boxes_file_name );
|
|
|
+}
|
|
|
+
|
|
|
int main(int argc, char *argv[])
|
|
|
{
|
|
|
QCoreApplication a(argc, argv);
|
|
|
|
|
|
+ test("/home/nvidia/Downloads/cbgs_pp_multihead_pfe.onnx",
|
|
|
+ "/home/nvidia/Downloads/cbgs_pp_multihead_backbone.onnx",
|
|
|
+ "/home/nvidia/code/modularization/src/detection/detection_lidar_PointPillars_MultiHead/cfgs/cbgs_pp_multihead.yaml");
|
|
|
return a.exec();
|
|
|
}
|