|
@@ -0,0 +1,390 @@
|
|
|
+#include <QCoreApplication>
|
|
|
+#include <pcl/io/pcd_io.h>
|
|
|
+
|
|
|
+#include "object.pb.h"
|
|
|
+#include "objectarray.pb.h"
|
|
|
+
|
|
|
+#include "modulecomm.h"
|
|
|
+#include "xmlparam.h"
|
|
|
+#include "ivfault.h"
|
|
|
+#include "ivlog.h"
|
|
|
+#include "ivexit.h"
|
|
|
+#include "ivversion.h"
|
|
|
+#include "rawpic.pb.cc"
|
|
|
+
|
|
|
+#include <string>
|
|
|
+#include <thread>
|
|
|
+#include <time.h>
|
|
|
+#include <opencv2/opencv.hpp>
|
|
|
+
|
|
|
+#include <sys/stat.h>
|
|
|
+#include <libgen.h>
|
|
|
+#include "imageBuffer.h"
|
|
|
+
|
|
|
+
|
|
|
+// save pointcloud data and front camera data
|
|
|
+void * gpa;
|
|
|
+void * gpcamera;
|
|
|
+void * gpcamera_front;
|
|
|
+void * gpcamera_back;
|
|
|
+void * gpcamera_left;
|
|
|
+void * gpcamera_right;
|
|
|
+
|
|
|
+std::string gstrinput = "lidar_pc";
|
|
|
+const std::string cameraname="image00";
|
|
|
+
|
|
|
+const std::string camerafront="picfront";
|
|
|
+const std::string camerarear="picrear";
|
|
|
+const std::string cameraleft="picleft";
|
|
|
+const std::string cameraright="picright";
|
|
|
+
|
|
|
+iv::Ivfault *gfault = nullptr;
|
|
|
+iv::Ivlog *givlog = nullptr;
|
|
|
+
|
|
|
+std::string strpath = "./savePosition.xml";
|
|
|
+
|
|
|
+iv::xmlparam::Xmlparam xp(strpath);
|
|
|
+std::string strDir_pointcloud = xp.GetParam("pointcloud_save_position","/home/nvidia/saveData/ivd");
|
|
|
+std::string strDir_middle = xp.GetParam("middle_save_position","/home/nvidia/saveData/middle");
|
|
|
+
|
|
|
+std::string strDir_front = xp.GetParam("front_save_position","/home/nvidia/saveData/front");
|
|
|
+std::string strDir_back = xp.GetParam("back_save_position","/home/nvidia/saveData/back");
|
|
|
+std::string strDir_left = xp.GetParam("left_save_position","/home/nvidia/saveData/left");
|
|
|
+std::string strDir_right = xp.GetParam("right_save_position","/home/nvidia/saveData/right");
|
|
|
+
|
|
|
+
|
|
|
+ConsumerProducerQueue<pcl::PointCloud<pcl::PointXYZI>::Ptr> * pcdBuffer_middle =
|
|
|
+ new ConsumerProducerQueue<pcl::PointCloud<pcl::PointXYZI>::Ptr>(1,false);
|
|
|
+ConsumerProducerQueue<cv::Mat> * imageBuffer_middle = new ConsumerProducerQueue<cv::Mat>(2,true);
|
|
|
+ConsumerProducerQueue<cv::Mat> * imageBuffer_front = new ConsumerProducerQueue<cv::Mat>(2,true);
|
|
|
+ConsumerProducerQueue<cv::Mat> * imageBuffer_back = new ConsumerProducerQueue<cv::Mat>(2,true);
|
|
|
+ConsumerProducerQueue<cv::Mat> * imageBuffer_left = new ConsumerProducerQueue<cv::Mat>(2,true);
|
|
|
+ConsumerProducerQueue<cv::Mat> * imageBuffer_right = new ConsumerProducerQueue<cv::Mat>(2,true);
|
|
|
+
|
|
|
+static bool check_exists(const std::string &file_path) {
|
|
|
+ return (access(file_path.c_str(), F_OK) != -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ static std::string get_parent_path(const std::string &path) {
|
|
|
+ char buf[1024];
|
|
|
+ strcpy(buf, path.c_str());
|
|
|
+ char *result = dirname(buf);
|
|
|
+ return std::string(result);
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建多级目录
|
|
|
+ static void create_directories(const std::string &path_dir) {
|
|
|
+ if (check_exists(path_dir)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ std::vector<std::string> path_list({path_dir});
|
|
|
+
|
|
|
+ std::string temp_dir_str = path_dir;
|
|
|
+ while (true) {
|
|
|
+ if ((temp_dir_str.find("/") != std::string::npos) &&
|
|
|
+ (temp_dir_str != "/")) {
|
|
|
+ temp_dir_str = get_parent_path(temp_dir_str);
|
|
|
+ if (!check_exists(temp_dir_str)) {
|
|
|
+ path_list.push_back(temp_dir_str);
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (auto iter = path_list.rbegin(); iter != path_list.rend(); ++iter) {
|
|
|
+ mkdir((*iter).c_str(), 0775);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+int pcdNum = 1;
|
|
|
+void ListenPointCloud(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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++)
|
|
|
+ {
|
|
|
+ pcl::PointXYZI xp;
|
|
|
+ memcpy(&xp,p,sizeof(pcl::PointXYZI));
|
|
|
+ xp.z = xp.z;
|
|
|
+ xp.intensity = xp.intensity;
|
|
|
+ if(xp.intensity>255)xp.intensity = 255;
|
|
|
+ if(xp.intensity<0)xp.intensity = 0;
|
|
|
+ point_cloud->push_back(xp);
|
|
|
+ p++;
|
|
|
+ }
|
|
|
+// pcl::io::savePCDFileASCII(strDir+std::to_string(pcdNum)+".pcd", *point_cloud);
|
|
|
+// time_t currentTime = std::time(NULL);
|
|
|
+// char chCurrentTime[64];
|
|
|
+// std::strftime(chCurrentTime, sizeof(chCurrentTime), "%Y%m%d%H%M%S", std::localtime(¤tTime));
|
|
|
+// std::string stCurrentTime = chCurrentTime;
|
|
|
+
|
|
|
+ auto now = std::chrono::system_clock::now();
|
|
|
+ long long millseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
|
|
|
+ std::string pcdname = std::to_string(millseconds);
|
|
|
+
|
|
|
+ pcdBuffer_middle->add(point_cloud);
|
|
|
+ //pcl::io::savePCDFileASCII(strDir_pointcloud+"/"+pcdname+".pcd", *point_cloud);
|
|
|
+ //std::cout<<"Saved "<<point_cloud->size()<<" data points to "<<strDir_pointcloud+"/"+pcdname+".pcd"<<std::endl;
|
|
|
+ pcdNum++;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void Listenpic(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize<1000)return;
|
|
|
+ iv::vision::rawpic pic;
|
|
|
+ if(false == pic.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"picview Listenpic fail."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cv::Mat mat(pic.height(),pic.width(),pic.mattype());
|
|
|
+ if(pic.type() == 1)
|
|
|
+ memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
|
|
|
+ mat = cv::imdecode(buff,cv::IMREAD_COLOR);
|
|
|
+ }
|
|
|
+ auto now = std::chrono::system_clock::now();
|
|
|
+ long long millseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
|
|
|
+ std::string picname = std::to_string(millseconds);
|
|
|
+ if(!mat.empty())
|
|
|
+ {
|
|
|
+ imageBuffer_middle->add(mat);
|
|
|
+ //cv::imwrite(strDir_middle+"/"+picname+".jpg", mat);
|
|
|
+ //std::cout<<"Saved "<<" camera data to "<<strDir_middle+"/"+picname+".jpg"<<std::endl;
|
|
|
+ }
|
|
|
+ mat.release();
|
|
|
+}
|
|
|
+
|
|
|
+void Listenpic_front(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize<1000)return;
|
|
|
+ iv::vision::rawpic pic;
|
|
|
+ if(false == pic.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"picview Listenpic fail."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cv::Mat mat(pic.height(),pic.width(),pic.mattype());
|
|
|
+ if(pic.type() == 1)
|
|
|
+ memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
|
|
|
+ mat = cv::imdecode(buff,cv::IMREAD_COLOR);
|
|
|
+ }
|
|
|
+ auto now = std::chrono::system_clock::now();
|
|
|
+ long long millseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
|
|
|
+ std::string picname = std::to_string(millseconds);
|
|
|
+
|
|
|
+ if(!mat.empty())
|
|
|
+ {
|
|
|
+ imageBuffer_front->add(mat);
|
|
|
+ //cv::imwrite(strDir_front+"/"+picname+".jpg", mat);
|
|
|
+ //std::cout<<"Saved "<<" camera data to "<<strDir_front+"/"+picname+".jpg"<<std::endl;
|
|
|
+ }
|
|
|
+ mat.release();
|
|
|
+}
|
|
|
+
|
|
|
+void Listenpic_back(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize<1000)return;
|
|
|
+ iv::vision::rawpic pic;
|
|
|
+ if(false == pic.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"picview Listenpic fail."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cv::Mat mat(pic.height(),pic.width(),pic.mattype());
|
|
|
+ if(pic.type() == 1)
|
|
|
+ memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
|
|
|
+ mat = cv::imdecode(buff,cv::IMREAD_COLOR);
|
|
|
+ }
|
|
|
+ auto now = std::chrono::system_clock::now();
|
|
|
+ long long millseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
|
|
|
+ std::string picname = std::to_string(millseconds);
|
|
|
+
|
|
|
+ if(!mat.empty())
|
|
|
+ {
|
|
|
+ imageBuffer_back->add(mat);
|
|
|
+ //cv::imwrite(strDir_back+"/"+picname+".jpg", mat);
|
|
|
+ //std::cout<<"Saved "<<" camera data to "<<strDir_back+"/"+picname+".jpg"<<std::endl;
|
|
|
+ }
|
|
|
+ mat.release();
|
|
|
+}
|
|
|
+
|
|
|
+void Listenpic_left(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize<1000)return;
|
|
|
+ iv::vision::rawpic pic;
|
|
|
+ if(false == pic.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"picview Listenpic fail."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cv::Mat mat(pic.height(),pic.width(),pic.mattype());
|
|
|
+ if(pic.type() == 1)
|
|
|
+ memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
|
|
|
+ mat = cv::imdecode(buff,cv::IMREAD_COLOR);
|
|
|
+ }
|
|
|
+ auto now = std::chrono::system_clock::now();
|
|
|
+ long long millseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
|
|
|
+ std::string picname = std::to_string(millseconds);
|
|
|
+
|
|
|
+ if(!mat.empty())
|
|
|
+ {
|
|
|
+ imageBuffer_left->add(mat);
|
|
|
+ //cv::imwrite(strDir_left+"/"+picname+".jpg", mat);
|
|
|
+ //std::cout<<"Saved "<<" camera data to "<<strDir_left+"/"+picname+".jpg"<<std::endl;
|
|
|
+ }
|
|
|
+ mat.release();
|
|
|
+}
|
|
|
+
|
|
|
+void Listenpic_right(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
|
|
|
+{
|
|
|
+ if(nSize<1000)return;
|
|
|
+ iv::vision::rawpic pic;
|
|
|
+ if(false == pic.ParseFromArray(strdata,nSize))
|
|
|
+ {
|
|
|
+ std::cout<<"picview Listenpic fail."<<std::endl;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ cv::Mat mat(pic.height(),pic.width(),pic.mattype());
|
|
|
+ if(pic.type() == 1)
|
|
|
+ memcpy(mat.data,pic.picdata().data(),mat.rows*mat.cols*mat.elemSize());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
|
|
|
+ mat = cv::imdecode(buff,cv::IMREAD_COLOR);
|
|
|
+ }
|
|
|
+ auto now = std::chrono::system_clock::now();
|
|
|
+ long long millseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
|
|
|
+ std::string picname = std::to_string(millseconds);
|
|
|
+
|
|
|
+ if(!mat.empty())
|
|
|
+ {
|
|
|
+ imageBuffer_right->add(mat);
|
|
|
+ //cv::imwrite(strDir_right+"/"+picname+".jpg", mat);
|
|
|
+ //std::cout<<"Saved "<<" camera data to "<<strDir_right+"/"+picname+".jpg"<<std::endl;
|
|
|
+ }
|
|
|
+ mat.release();
|
|
|
+}
|
|
|
+
|
|
|
+void exitfunc()
|
|
|
+{
|
|
|
+ std::cout<<"state thread closed."<<std::endl;
|
|
|
+ iv::modulecomm::Unregister(gpa);
|
|
|
+ iv::modulecomm::Unregister(gpcamera);
|
|
|
+ iv::modulecomm::Unregister(gpcamera_front);
|
|
|
+ iv::modulecomm::Unregister(gpcamera_back);
|
|
|
+ iv::modulecomm::Unregister(gpcamera_left);
|
|
|
+ iv::modulecomm::Unregister(gpcamera_right);
|
|
|
+ std::cout<<"exit func complete"<<std::endl;
|
|
|
+}
|
|
|
+
|
|
|
+int main(int argc, char *argv[])
|
|
|
+{
|
|
|
+ gfault = new iv::Ivfault("adciv_save");
|
|
|
+ givlog = new iv::Ivlog("adciv_save");
|
|
|
+ gfault->SetFaultState(0,0,"adciv_save initialize. ");
|
|
|
+ showversion("save_lidar_data");
|
|
|
+ QCoreApplication a(argc, argv);
|
|
|
+
|
|
|
+ create_directories(strDir_pointcloud);
|
|
|
+ create_directories(strDir_middle);
|
|
|
+ create_directories(strDir_front);
|
|
|
+ create_directories(strDir_back);
|
|
|
+ create_directories(strDir_left);
|
|
|
+ create_directories(strDir_right);
|
|
|
+
|
|
|
+ gpa = iv::modulecomm::RegisterRecv(gstrinput.data(),ListenPointCloud);
|
|
|
+ gpcamera= iv::modulecomm::RegisterRecv(&cameraname[0],Listenpic);
|
|
|
+ gpcamera_front= iv::modulecomm::RegisterRecv(&camerafront[0],Listenpic_front);
|
|
|
+ gpcamera_back= iv::modulecomm::RegisterRecv(&camerarear[0],Listenpic_back);
|
|
|
+ gpcamera_left= iv::modulecomm::RegisterRecv(&cameraleft[0],Listenpic_left);
|
|
|
+ gpcamera_right= iv::modulecomm::RegisterRecv(&cameraright[0],Listenpic_right);
|
|
|
+
|
|
|
+ cv::Mat picfront,picback,picleft,picright,picmiddle;
|
|
|
+
|
|
|
+ pcl::PointCloud<pcl::PointXYZI>::Ptr point_cloud(
|
|
|
+ new pcl::PointCloud<pcl::PointXYZI>());
|
|
|
+
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
+
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ auto now = std::chrono::system_clock::now();
|
|
|
+ long long millseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count();
|
|
|
+ std::string filename = std::to_string(millseconds);
|
|
|
+
|
|
|
+ if (pcdBuffer_middle->isEmpty() || imageBuffer_front->isEmpty()|| imageBuffer_back->isEmpty() ||
|
|
|
+ imageBuffer_left->isEmpty()|| imageBuffer_right->isEmpty() || imageBuffer_middle->isEmpty())
|
|
|
+ {
|
|
|
+
|
|
|
+ std::cout<<"Wait data"<<std::endl;
|
|
|
+ if(imageBuffer_middle->isEmpty())
|
|
|
+ std::cout<<"middle senyun image is empty"<<std::endl;
|
|
|
+
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ pcdBuffer_middle->consume(point_cloud);
|
|
|
+ imageBuffer_front->consume(picfront);
|
|
|
+ imageBuffer_back->consume(picback);
|
|
|
+ imageBuffer_left->consume(picleft);
|
|
|
+ imageBuffer_right->consume(picright);
|
|
|
+ imageBuffer_middle->consume(picmiddle);
|
|
|
+
|
|
|
+
|
|
|
+ if((!picfront.empty()) && (!picback.empty()) && (!picleft.empty()) && (!picright.empty())
|
|
|
+ && (!picmiddle.empty()))
|
|
|
+ {
|
|
|
+ pcl::io::savePCDFileASCII(strDir_pointcloud+"/"+filename+".pcd", *point_cloud);
|
|
|
+ cv::imwrite(strDir_front+"/"+filename+".jpg", picfront);
|
|
|
+ cv::imwrite(strDir_back+"/"+filename+".jpg", picback);
|
|
|
+ cv::imwrite(strDir_left+"/"+filename+".jpg", picleft);
|
|
|
+ cv::imwrite(strDir_right+"/"+filename+".jpg", picright);
|
|
|
+ cv::imwrite(strDir_middle+"/"+filename+".jpg", picmiddle);
|
|
|
+ std::cout<<"Saved "<<" camera data to "<<filename+".jpg"<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ iv::ivexit::RegIVExitCall(exitfunc);
|
|
|
+
|
|
|
+ return a.exec();
|
|
|
+}
|