|
@@ -19,6 +19,12 @@
|
|
|
//#include "alog.h"
|
|
|
|
|
|
CNNSegmentation gcnn;
|
|
|
+CNNSegmentation gcnnv[10];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+iv::pcbuffer gpcbuffer;
|
|
|
+std::mutex gmutexpcbuffer;
|
|
|
|
|
|
void * gpa;
|
|
|
void * gpdetect;
|
|
@@ -30,6 +36,8 @@ std::thread * gpthread;
|
|
|
std::string gstrinput;
|
|
|
std::string gstroutput;
|
|
|
|
|
|
+bool gbUseMultiCNN = false;
|
|
|
+
|
|
|
static iv::lidar::PointXYZ pcltoprotopoint(pcl::PointXYZ x)
|
|
|
{
|
|
|
iv::lidar::PointXYZ lx;
|
|
@@ -245,48 +253,117 @@ static void GetLidarObj(std::vector<Obstacle> objvec,iv::lidar::objectarray & li
|
|
|
void DectectOnePCD(const pcl::PointCloud<pcl::PointXYZI>::Ptr &pc_ptr)
|
|
|
{
|
|
|
std::cout<<"pcd size is "<<pc_ptr->size()<<std::endl;
|
|
|
- pcl::PointIndices valid_idx;
|
|
|
- auto &indices = valid_idx.indices;
|
|
|
- indices.resize(pc_ptr->size());
|
|
|
- std::iota(indices.begin(), indices.end(), 0);
|
|
|
|
|
|
- std::vector<Obstacle> objvec;
|
|
|
|
|
|
- gcnn.segment(pc_ptr, valid_idx, objvec);
|
|
|
- givlog->verbose("obj size is %d", objvec.size());
|
|
|
- std::cout<<"obj size is "<<objvec.size()<<std::endl;
|
|
|
+ bool bUseMutliCluster = true;
|
|
|
|
|
|
-// std::vector<iv::lidar::lidarobject> lidarobjvec;
|
|
|
- iv::lidar::objectarray lidarobjvec;
|
|
|
- GetLidarObj(objvec,lidarobjvec);
|
|
|
+ if(bUseMutliCluster == false)
|
|
|
+ {
|
|
|
+ pcl::PointIndices valid_idx;
|
|
|
+ auto &indices = valid_idx.indices;
|
|
|
+ indices.resize(pc_ptr->size());
|
|
|
+ std::iota(indices.begin(), indices.end(), 0);
|
|
|
+ std::vector<Obstacle> objvec;
|
|
|
+ gcnn.segment(pc_ptr, valid_idx, objvec);
|
|
|
+ givlog->verbose("obj size is %d", objvec.size());
|
|
|
+ std::cout<<"obj size is "<<objvec.size()<<std::endl;
|
|
|
+
|
|
|
+ // std::vector<iv::lidar::lidarobject> lidarobjvec;
|
|
|
+ iv::lidar::objectarray lidarobjvec;
|
|
|
+ GetLidarObj(objvec,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();
|
|
|
+ // char * strout = lidarobjtostr(lidarobjvec,ntlen);
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpdetect,out.data(),out.length());
|
|
|
+ givlog->verbose("lenth is %d",out.length());
|
|
|
+ // delete strout;
|
|
|
+
|
|
|
+ // int i;
|
|
|
+ // for(i=0;i<objvec.size();i++)
|
|
|
+ // {
|
|
|
+ // Obstacle x;
|
|
|
+ // x = objvec.at(i);
|
|
|
+
|
|
|
+ // std::cout<<"obj "<<i<<" x is "<<x.GetTypeString()<<std::endl;
|
|
|
+
|
|
|
+ // iv::lidar::lidarobject y;
|
|
|
+ // y = lidarobjvec.at(i);
|
|
|
+ // std::cout<<" "<<" x is"<<y.position.x<<" y is "<<y.position.y<<" len x is "<<y.dimensions.x<<" len y is "<<y.dimensions.y<<std::endl;
|
|
|
+ // std::cout<<" "<<" type is "<<y.mnType<<std::endl;
|
|
|
+ // }
|
|
|
|
|
|
- double timex = pc_ptr->header.stamp;
|
|
|
- timex = timex/1000.0;
|
|
|
- lidarobjvec.set_timestamp(pc_ptr->header.stamp);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pcl::PointIndicesPtr valid_idx_ptr = boost::shared_ptr<pcl::PointIndices>(new pcl::PointIndices());
|
|
|
+ auto &indices = valid_idx_ptr->indices;
|
|
|
+ indices.resize(pc_ptr->size());
|
|
|
+ std::iota(indices.begin(), indices.end(), 0);
|
|
|
+ gcnn.segment(pc_ptr, valid_idx_ptr);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- int ntlen;
|
|
|
- std::string out = lidarobjvec.SerializeAsString();
|
|
|
- // char * strout = lidarobjtostr(lidarobjvec,ntlen);
|
|
|
- iv::modulecomm::ModuleSendMsg(gpdetect,out.data(),out.length());
|
|
|
- givlog->verbose("lenth is %d",out.length());
|
|
|
- // delete strout;
|
|
|
|
|
|
-// int i;
|
|
|
-// for(i=0;i<objvec.size();i++)
|
|
|
-// {
|
|
|
-// Obstacle x;
|
|
|
-// x = objvec.at(i);
|
|
|
+void threadgetres()
|
|
|
+{
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ iv::cnnres xcnnres;
|
|
|
+ int nrtn = gcnn.GetRes(xcnnres);
|
|
|
+ if(nrtn == 1)
|
|
|
+ {
|
|
|
+ iv::lidar::objectarray lidarobjvec;
|
|
|
+ GetLidarObj(xcnnres.mobjvec,lidarobjvec);
|
|
|
+ std::string out = lidarobjvec.SerializeAsString();
|
|
|
+ // char * strout = lidarobjtostr(lidarobjvec,ntlen);
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpdetect,out.data(),out.length());
|
|
|
+
|
|
|
+ int64 now = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
|
|
|
+ std::cout<<" pc time : "<<xcnnres.mcluster2ddata.mPointCloudUpdateTime<<" cnn use: "<<(now - xcnnres.mcluster2ddata.mPointCloudUpdateTime)
|
|
|
+ <<" obj size: "<<xcnnres.mobjvec.size()<<std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
-// std::cout<<"obj "<<i<<" x is "<<x.GetTypeString()<<std::endl;
|
|
|
+void DectectOnePCD(const pcl::PointCloud<pcl::PointXYZI>::Ptr &pc_ptr,CNNSegmentation * pcnn)
|
|
|
+{
|
|
|
+ std::cout<<"pcd size is "<<pc_ptr->size()<<std::endl;
|
|
|
|
|
|
-// iv::lidar::lidarobject y;
|
|
|
-// y = lidarobjvec.at(i);
|
|
|
-// std::cout<<" "<<" x is"<<y.position.x<<" y is "<<y.position.y<<" len x is "<<y.dimensions.x<<" len y is "<<y.dimensions.y<<std::endl;
|
|
|
-// std::cout<<" "<<" type is "<<y.mnType<<std::endl;
|
|
|
-// }
|
|
|
-}
|
|
|
|
|
|
|
|
|
+ pcl::PointIndices valid_idx;
|
|
|
+ auto &indices = valid_idx.indices;
|
|
|
+ indices.resize(pc_ptr->size());
|
|
|
+ std::iota(indices.begin(), indices.end(), 0);
|
|
|
+ std::vector<Obstacle> objvec;
|
|
|
+ pcnn->segment(pc_ptr, valid_idx, objvec);
|
|
|
+ givlog->verbose("obj size is %d", objvec.size());
|
|
|
+ std::cout<<"obj size is "<<objvec.size()<<std::endl;
|
|
|
+
|
|
|
+ // std::vector<iv::lidar::lidarobject> lidarobjvec;
|
|
|
+ iv::lidar::objectarray lidarobjvec;
|
|
|
+ GetLidarObj(objvec,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();
|
|
|
+ // char * strout = lidarobjtostr(lidarobjvec,ntlen);
|
|
|
+ iv::modulecomm::ModuleSendMsg(gpdetect,out.data(),out.length());
|
|
|
+ givlog->verbose("lenth is %d",out.length());
|
|
|
+}
|
|
|
+
|
|
|
int gnothavedatatime = 0;
|
|
|
|
|
|
void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
@@ -341,12 +418,62 @@ void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsign
|
|
|
|
|
|
// std::cout<<"pcl time is "<<xTime.elapsed()<<std::endl;
|
|
|
|
|
|
- DectectOnePCD(point_cloud);
|
|
|
- std::cout<<"time is "<<(QDateTime::currentMSecsSinceEpoch() % 1000)<<" "<<xTime.elapsed()<<std::endl;
|
|
|
+ bool bUseMultiCNN = gbUseMultiCNN;
|
|
|
+ if(bUseMultiCNN)
|
|
|
+ {
|
|
|
+ gmutexpcbuffer.lock();
|
|
|
+ gpcbuffer.mbNew = true;
|
|
|
+ gpcbuffer.mpointcloud = point_cloud;
|
|
|
+ gpcbuffer.mPointCloudUpdateTime = std::chrono::system_clock::now().time_since_epoch().count()/1000000;
|
|
|
+ gmutexpcbuffer.unlock();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ DectectOnePCD(point_cloud);
|
|
|
+ }
|
|
|
+
|
|
|
+// std::cout<<"time is "<<(QDateTime::currentMSecsSinceEpoch() % 1000)<<" "<<xTime.elapsed()<<std::endl;
|
|
|
gfault->SetFaultState(0, 0, "ok");
|
|
|
|
|
|
}
|
|
|
|
|
|
+void threadcnn(std::string protofile,std::string weightfile,double range,int width,int height)
|
|
|
+{
|
|
|
+ CNNSegmentation cnn;
|
|
|
+ cnn.init(protofile,weightfile,60.0,0.6,1024,1024,false,true,0);
|
|
|
+
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud;
|
|
|
+
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ bool bNew = false;
|
|
|
+ int64 npctime;
|
|
|
+ gmutexpcbuffer.lock();
|
|
|
+ if(gpcbuffer.mbNew)
|
|
|
+ {
|
|
|
+ gpcbuffer.mbNew = false;
|
|
|
+ bNew = true;
|
|
|
+ point_cloud = gpcbuffer.mpointcloud;
|
|
|
+ npctime = gpcbuffer.mPointCloudUpdateTime;
|
|
|
+ }
|
|
|
+ gmutexpcbuffer.unlock();
|
|
|
+
|
|
|
+ if(bNew == false)
|
|
|
+ {
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ DectectOnePCD(point_cloud,&cnn);
|
|
|
+ std::cout<<"pc time: is "<<npctime<<" res use time: "<<(std::chrono::system_clock::now().time_since_epoch().count()/1000000 - npctime)<<std::endl;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
bool gbstate = true;
|
|
|
void statethread()
|
|
|
{
|
|
@@ -449,9 +576,37 @@ int main(int argc, char *argv[])
|
|
|
gstrinput = xparam.GetParam("input","lidar_pc");
|
|
|
gstroutput = xparam.GetParam("output","lidar_cnn_dectect");
|
|
|
|
|
|
+ double range,width,height;
|
|
|
+ range = xparam.GetParam("range",60.0);
|
|
|
+ width = xparam.GetParam("width",1024);
|
|
|
+ height = xparam.GetParam("height",1024);
|
|
|
+ int ncnn = xparam.GetParam("ncnn",2);
|
|
|
+
|
|
|
// std::string protofile = "/home/yuchuli/qt/bq/models/lidar/model.prototxt";
|
|
|
// std::string weightfile = "/home/yuchuli/qt/bq/models/lidar/model.caffemodel";
|
|
|
- gcnn.init(protofile,weightfile,60.0,0.6,512,512,false,true,0);
|
|
|
+ gcnn.init(protofile,weightfile,range,0.6,width,height,false,true,0);
|
|
|
+
|
|
|
+// int i;
|
|
|
+// for(i=0;i<3;i++)
|
|
|
+// {
|
|
|
+// gcnnv[i].init(protofile,weightfile,60.0,0.6,1024,1024,false,true,0);
|
|
|
+
|
|
|
+// }
|
|
|
+
|
|
|
+ std::thread * pthreadv[10];
|
|
|
+ if(gbUseMultiCNN)
|
|
|
+ {
|
|
|
+ int i;
|
|
|
+ if(ncnn>10)ncnn = 10;
|
|
|
+ for(i=0;i<ncnn;i++)
|
|
|
+ {
|
|
|
+ pthreadv[i] = new std::thread(threadcnn,protofile,weightfile,range,width,height);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ std::thread * pthreadsend = new std::thread(threadgetres);
|
|
|
+
|
|
|
|
|
|
|
|
|
|