|
@@ -1,18 +1,35 @@
|
|
|
#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>
|
|
|
+#include "xmlparam.h"
|
|
|
+#include "modulecomm.h"
|
|
|
+#include "ivfault.h"
|
|
|
+#include "ivlog.h"
|
|
|
+#include "ivexit.h"
|
|
|
+#include "ivversion.h"
|
|
|
+#include <thread>
|
|
|
+#include "objectarray.pb.h"
|
|
|
+//#include "ivbacktrace.h"
|
|
|
+
|
|
|
+iv::Ivfault *gfault = nullptr;
|
|
|
+iv::Ivlog *givlog = nullptr;
|
|
|
+
|
|
|
+std::thread * gpthread;
|
|
|
+PointPillars * pPillars = nullptr ;
|
|
|
+void * gpa;
|
|
|
+void * gpdetect;
|
|
|
+int gnothavedatatime = 0;
|
|
|
+const int kNumPointFeature = 5;
|
|
|
+const int kOutputNumBoxFeature = 7;
|
|
|
+std::string gstrinput;
|
|
|
+std::string gstroutput;
|
|
|
+
|
|
|
|
|
|
void PclToArray(
|
|
|
const pcl::PointCloud<pcl::PointXYZI>::Ptr& in_pcl_pc_ptr,
|
|
@@ -41,103 +58,255 @@ void PclXYZITToArray(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void Boxes2Txt( std::vector<float> boxes , string file_name , int num_feature = 7)
|
|
|
+void GetLidarObj(std::vector<float> out_detections,std::vector<int> out_labels,
|
|
|
+ std::vector<float> out_scores,iv::lidar::objectarray & lidarobjvec)
|
|
|
{
|
|
|
- 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";
|
|
|
- }
|
|
|
+ int i;
|
|
|
+ int obj_size = out_detections.size()/kOutputNumBoxFeature;
|
|
|
+// givlog->verbose("OBJ","object size is %d",obj_size);
|
|
|
+ for(i=0;i<obj_size;i++)
|
|
|
+ {
|
|
|
+ if (out_scores.at(i) < 0.10) continue;
|
|
|
+ iv::lidar::lidarobject lidarobj;
|
|
|
+ lidarobj.set_tyaw(out_detections.at(i*7+6));
|
|
|
+ iv::lidar::PointXYZ centroid;
|
|
|
+ iv::lidar::PointXYZ * _centroid;
|
|
|
+ centroid.set_x(out_detections.at(i*7));
|
|
|
+ centroid.set_y(out_detections.at(i*7+1));
|
|
|
+ centroid.set_z(out_detections.at(i*7+2));
|
|
|
+ _centroid = lidarobj.mutable_centroid();
|
|
|
+ _centroid->CopyFrom(centroid);
|
|
|
+
|
|
|
+ iv::lidar::PointXYZ min_point;
|
|
|
+ iv::lidar::PointXYZ * _min_point;
|
|
|
+ min_point.set_x(0);
|
|
|
+ min_point.set_y(0);
|
|
|
+ min_point.set_z(0);
|
|
|
+ _min_point = lidarobj.mutable_min_point();
|
|
|
+ _min_point->CopyFrom(min_point);
|
|
|
+
|
|
|
+ iv::lidar::PointXYZ max_point;
|
|
|
+ iv::lidar::PointXYZ * _max_point;
|
|
|
+ max_point.set_x(0);
|
|
|
+ max_point.set_y(0);
|
|
|
+ max_point.set_z(0);
|
|
|
+ _max_point = lidarobj.mutable_max_point();
|
|
|
+ _max_point->CopyFrom(max_point);
|
|
|
+
|
|
|
+ iv::lidar::PointXYZ position;
|
|
|
+ iv::lidar::PointXYZ * _position;
|
|
|
+ position.set_x(out_detections.at(i*7));
|
|
|
+ position.set_y(out_detections.at(i*7+1));
|
|
|
+ position.set_z(out_detections.at(i*7+2));
|
|
|
+ _position = lidarobj.mutable_position();
|
|
|
+ _position->CopyFrom(position);
|
|
|
+
|
|
|
+ lidarobj.set_mntype(out_labels.at(i));
|
|
|
+ lidarobj.set_score(out_scores.at(i));
|
|
|
+ lidarobj.add_type_probs(out_scores.at(i));
|
|
|
+
|
|
|
+ iv::lidar::PointXYZI point_cloud;
|
|
|
+ iv::lidar::PointXYZI * _point_cloud;
|
|
|
+ point_cloud.set_x(out_detections.at(i*7));
|
|
|
+ point_cloud.set_y(out_detections.at(i*7+1));
|
|
|
+ point_cloud.set_z(out_detections.at(i*7+2));
|
|
|
+ point_cloud.set_i(out_detections.at(out_labels.at(i)));
|
|
|
+ _point_cloud = lidarobj.add_cloud();
|
|
|
+ _point_cloud->CopyFrom(point_cloud);
|
|
|
+
|
|
|
+ iv::lidar::Dimension ld;
|
|
|
+ iv::lidar::Dimension * pld;
|
|
|
+ ld.set_x(out_detections.at(i*7+3));
|
|
|
+ ld.set_y(out_detections.at(i*7+4));
|
|
|
+ ld.set_z(out_detections.at(i*7+5));
|
|
|
+ pld = lidarobj.mutable_dimensions();
|
|
|
+ pld->CopyFrom(ld);
|
|
|
+
|
|
|
+ iv::lidar::lidarobject * po = lidarobjvec.add_obj();
|
|
|
+ po->CopyFrom(lidarobj);
|
|
|
}
|
|
|
- ofFile.close();
|
|
|
- return ;
|
|
|
-};
|
|
|
-
|
|
|
+}
|
|
|
|
|
|
-void test(std::string pfe_file,std::string backbone_file,std::string pp_config)
|
|
|
+void DectectOnePCD(const pcl::PointCloud<pcl::PointXYZI>::Ptr &pc_ptr)
|
|
|
{
|
|
|
+ float* points_array = new float[pc_ptr->size() * kNumPointFeature];
|
|
|
+ PclXYZITToArray(pc_ptr, points_array, 1.0);
|
|
|
|
|
|
- PointPillars * pPillars;
|
|
|
- pPillars = new PointPillars(
|
|
|
- 0.1,
|
|
|
- 0.2,
|
|
|
- true,
|
|
|
- pfe_file,
|
|
|
- backbone_file,
|
|
|
- pp_config
|
|
|
- );
|
|
|
- std::cout<<"PointPillars Init OK."<<std::endl;
|
|
|
+ int in_num_points = pc_ptr->width;
|
|
|
|
|
|
- pcl::PointCloud<pcl::PointXYZI>::Ptr xpc(
|
|
|
- new pcl::PointCloud<pcl::PointXYZI>);
|
|
|
+ std::vector<float> out_detections;
|
|
|
+ std::vector<int> out_labels;
|
|
|
+ std::vector<float> out_scores;
|
|
|
|
|
|
+ QTime xTime;
|
|
|
|
|
|
- pcl::PointCloud<pcl::PointXYZI>::Ptr xpcfile;
|
|
|
+ xTime.start();
|
|
|
|
|
|
- xpcfile = boost::shared_ptr<pcl::PointCloud<pcl::PointXYZI>>(new pcl::PointCloud<pcl::PointXYZI>);
|
|
|
+ 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;
|
|
|
|
|
|
- if(0 == pcl::io::loadPCDFile("/home/nvidia/20200604054241688.pcd",*xpc))
|
|
|
- {
|
|
|
+// givlog->verbose("obj size is %d", num_objects);
|
|
|
+// std::cout<<"obj size is "<<num_objects<<std::endl;
|
|
|
|
|
|
+// std::vector<iv::lidar::lidarobject> lidarobjvec;
|
|
|
+ iv::lidar::objectarray lidarobjvec;
|
|
|
+ GetLidarObj(out_detections,out_labels,out_scores,lidarobjvec);
|
|
|
+
|
|
|
+ double timex = pc_ptr->header.stamp;
|
|
|
+ timex = timex/1000.0;
|
|
|
+ lidarobjvec.set_timestamp(pc_ptr->header.stamp);
|
|
|
+
|
|
|
+ int ntlen;
|
|
|
+ std::string out = lidarobjvec.SerializeAsString();
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpdetect,out.data(),out.length());
|
|
|
+// givlog->verbose("lenth is %d",out.length());
|
|
|
+}
|
|
|
+
|
|
|
+void ListenPointCloud(const char *strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+// std::cout<<" is ok ------------ "<<std::endl;
|
|
|
+ if(nSize <=16)return;
|
|
|
+ unsigned int * pHeadSize = (unsigned int *)strdata;
|
|
|
+ if(*pHeadSize > nSize)
|
|
|
+ {
|
|
|
+ givlog->verbose("ListenPointCloud data is small headsize = %d, data size is %d", *pHeadSize, nSize);
|
|
|
+ std::cout<<"ListenPointCloud data is small headsize ="<<*pHeadSize<<" data size is"<<nSize<<std::endl;
|
|
|
}
|
|
|
- else
|
|
|
+
|
|
|
+ gnothavedatatime = 0;
|
|
|
+ QTime xTime;
|
|
|
+ xTime.start();
|
|
|
+
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
|
|
|
+ new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
+ int nNameSize;
|
|
|
+ nNameSize = *pHeadSize - 4-4-8;
|
|
|
+ char * strName = new char[nNameSize+1];strName[nNameSize] = 0;
|
|
|
+ memcpy(strName,(char *)((char *)strdata +4),nNameSize);
|
|
|
+ point_cloud->header.frame_id = strName;
|
|
|
+ memcpy(&point_cloud->header.seq,(char *)strdata+4+nNameSize,4);
|
|
|
+ memcpy(&point_cloud->header.stamp,(char *)strdata+4+nNameSize+4,8);
|
|
|
+ int nPCount = (nSize - *pHeadSize)/sizeof(pcl::PointXYZI);
|
|
|
+ int i;
|
|
|
+ pcl::PointXYZI * p;
|
|
|
+ p = (pcl::PointXYZI *)((char *)strdata + *pHeadSize);
|
|
|
+ for(i=0;i<nPCount;i++)
|
|
|
{
|
|
|
- std::cout<<"load pcd fail"<<std::endl;
|
|
|
- return;
|
|
|
+ pcl::PointXYZI xp;
|
|
|
+ memcpy(&xp,p,sizeof(pcl::PointXYZI));
|
|
|
+ xp.z = xp.z;
|
|
|
+ point_cloud->push_back(xp);
|
|
|
+ p++;
|
|
|
}
|
|
|
|
|
|
- const int kNumPointFeature = 5;
|
|
|
- const int kOutputNumBoxFeature = 7;
|
|
|
+ DectectOnePCD(point_cloud);
|
|
|
+ std::cout<<"time is "<<(QDateTime::currentMSecsSinceEpoch() % 1000)<<" "<<xTime.elapsed()<<std::endl;
|
|
|
+ gfault->SetFaultState(0, 0, "ok");
|
|
|
|
|
|
+}
|
|
|
|
|
|
-// 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);
|
|
|
-// }
|
|
|
+bool gbstate = true;
|
|
|
+void statethread()
|
|
|
+{
|
|
|
+ int nstate = 0;
|
|
|
+ int nlaststate = 0;
|
|
|
+ while (gbstate)
|
|
|
+ {
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
|
+ if(gnothavedatatime < 100000) gnothavedatatime++;
|
|
|
|
|
|
- std::cout<<"point size is "<<xpc->width<<std::endl;
|
|
|
+ if (gnothavedatatime < 100){
|
|
|
+ nstate = 0;
|
|
|
+ }
|
|
|
+ if (gnothavedatatime > 1000)
|
|
|
+ {
|
|
|
+ nstate = 1;
|
|
|
+ }
|
|
|
+ if (gnothavedatatime > 6000)
|
|
|
+ {
|
|
|
+ nstate = 2;
|
|
|
+ }
|
|
|
+ if (nstate != nlaststate) {
|
|
|
+ switch (nstate) {
|
|
|
+ case 0:
|
|
|
+ givlog->info("detection_lidar_pointpillar is ok");
|
|
|
+ gfault->SetFaultState(0,0,"data is ok.");
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ givlog->info(" more than 10 seconds not have lidar pointcloud.");
|
|
|
+ gfault->SetFaultState(1,1,"more than 10 seconds not have lidar pointcloud.");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ givlog->info(" more than 60 seconds not have lidar pointcloud.");
|
|
|
+ gfault->SetFaultState(2,2, "more than 60 seconds not have lidar pointcloud.");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+void exitfunc()
|
|
|
+{
|
|
|
+ gbstate = false;
|
|
|
+ gpthread->join();
|
|
|
+ std::cout<<" state thread closed."<<std::endl;
|
|
|
+ iv::modulecomm::Unregister(gpa);
|
|
|
+ iv::modulecomm::Unregister(gpdetect);
|
|
|
+ std::cout<<"exit func complete"<<std::endl;
|
|
|
+}
|
|
|
|
|
|
- float* points_array = new float[xpc->size() * kNumPointFeature];
|
|
|
- PclXYZITToArray(xpc, points_array, 1.0);
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ QCoreApplication a(argc, argv);
|
|
|
|
|
|
- int in_num_points = xpc->width;
|
|
|
+// RegisterIVBackTrace();
|
|
|
|
|
|
- std::vector<float> out_detections;
|
|
|
- std::vector<int> out_labels;
|
|
|
- std::vector<float> out_scores;
|
|
|
+ gfault = new iv::Ivfault("lidar_pointpillar");
|
|
|
+ givlog = new iv::Ivlog("lidar_pointpillar");
|
|
|
|
|
|
- QTime xTime;
|
|
|
+ gfault->SetFaultState(0,0,"pointpillar initialize. ");
|
|
|
|
|
|
- xTime.start();
|
|
|
+ char * strhome = getenv("HOME");
|
|
|
+ std::string pfe_file = strhome;
|
|
|
+ pfe_file += "/models/lidar/cbgs_pp_multihead_pfe.onnx";
|
|
|
+ std::string backbone_file = strhome;
|
|
|
+ backbone_file += "/models/lidar/cbgs_pp_multihead_backbone.onnx";
|
|
|
|
|
|
- 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;
|
|
|
+ QString strpath = QCoreApplication::applicationDirPath();
|
|
|
+ std::string pp_config = strpath.toStdString() ;
|
|
|
+ pp_config += "/cfgs/cbgs_pp_multihead.yaml";
|
|
|
+ if (argc < 2)
|
|
|
+ strpath = strpath + "/detection_lidar_pointpillar.xml";
|
|
|
+ else
|
|
|
+ strpath = argv[1];
|
|
|
|
|
|
- std::string boxes_file_name = "/home/nvidia/pointpillarsout.txt";
|
|
|
- Boxes2Txt(out_detections , boxes_file_name );
|
|
|
-}
|
|
|
+ std::cout<<pp_config<<std::endl;
|
|
|
|
|
|
-int main(int argc, char *argv[])
|
|
|
-{
|
|
|
- QCoreApplication a(argc, argv);
|
|
|
+ iv::xmlparam::Xmlparam xparam(strpath.toStdString());
|
|
|
+ pfe_file = xparam.GetParam("pfe_file",pfe_file.data());
|
|
|
+ backbone_file = xparam.GetParam("backbone_file",backbone_file.data());
|
|
|
+ gstrinput = xparam.GetParam("input","lidar_pc");
|
|
|
+ gstroutput = xparam.GetParam("output","lidar_pointpillar");
|
|
|
+ pPillars = new PointPillars(
|
|
|
+ 0.1,
|
|
|
+ 0.2,
|
|
|
+ true,
|
|
|
+ pfe_file,
|
|
|
+ backbone_file,
|
|
|
+ pp_config
|
|
|
+ );
|
|
|
+ std::cout<<"PointPillars Init OK."<<std::endl;
|
|
|
+
|
|
|
+ gpa = iv::modulecomm::RegisterRecv(gstrinput.data(),ListenPointCloud);
|
|
|
+ gpdetect = iv::modulecomm::RegisterSend(gstroutput.data(), 10000000,1);
|
|
|
+ gpthread = new std::thread(statethread);
|
|
|
|
|
|
- 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");
|
|
|
+ iv::ivexit::RegIVExitCall(exitfunc);
|
|
|
return a.exec();
|
|
|
}
|