1111#include " cca.cc"
1212#include < map>
1313
14+ #include < boost/filesystem.hpp>
15+
1416#include < assert.h>
1517namespace LaneDetect {
18+ namespace bf = boost::filesystem;// 简单别名
19+
1620
1721void Aggregation::Process (const std::deque<Frame> &data_buffer, const Eigen::Matrix4f &world_imu, const Eigen::Matrix4f &imu_vel,
18- int frame_size, pcl::PointCloud<PPoint>::Ptr& pc, pcl::PointCloud<PPoint>::Ptr& labelpc) {
22+ int frame_size, pcl::PointCloud<PPoint>::Ptr &pc, pcl::PointCloud<PPoint>::Ptr &labelpc,
23+ uint64_t timestamp) {
1924
2025 if (data_buffer.size () <= frame_size) {
2126 return ;
@@ -228,24 +233,24 @@ void Aggregation::Process(const std::deque<Frame> &data_buffer, const Eigen::Mat
228233 double dur = elap_timet.toSec ();
229234 ROS_INFO (" CCA time: %f" ,dur);
230235
231- std::map<int ,int > label_map;
232- std::map<int ,int > label_map_idx;
236+ std::map<int ,int > label_map; // label : cnt(0 -> n)
237+ std::map<int ,int > label_map_idx; // label : label_idx(2 -> n-2)
238+ std::map<int ,std::vector<cv::Point>> label_map_point;
233239 int labelcnt = 2 ;
234240 for (auto &si:labels){
235241 label_map[si] = label_map.size ();
236242 label_map_idx[si] = labelcnt;
243+ label_map_point[si] = std::vector<cv::Point>();
237244 labelcnt++;
238245 }
239246
240-
241247 std::vector<cv::Vec3b> color_table;
242248 for (size_t ci = 0 ; ci < labels.size ()+10 ; ++ci) {
243249 color_table.emplace_back (cv::Vec3b (rand ()%255 , rand ()%255 , rand ()%255 ));
244250 }
245251 cv::Mat color_label;
246252 cv::cvtColor (img, color_label, CV_GRAY2BGR);
247253
248-
249254 for (int row = 0 ; row < _lableImg.rows ; ++row) {
250255 for (int col = 0 ; col < _lableImg.cols ; ++col) {
251256 const int &label = _lableImg.at <int >(row, col);
@@ -254,13 +259,70 @@ void Aggregation::Process(const std::deque<Frame> &data_buffer, const Eigen::Mat
254259 color_label.at <cv::Vec3b>(row,col)[0 ] = color_table.at (idx).val [0 ];
255260 color_label.at <cv::Vec3b>(row,col)[1 ] = color_table.at (idx).val [1 ];
256261 color_label.at <cv::Vec3b>(row,col)[2 ] = color_table.at (idx).val [2 ];
262+
263+ label_map_point[idx].emplace_back (cv::Point (col, row));
257264 }
258265 }
259266 }
267+
260268// cv::imshow("_lableImg",_lableImg);
269+ // cv::imshow("color_label",color_label);
270+ // cv::waitKey(15);
271+
272+
273+ // ///// check all the points
274+ std::string save_dir = " /tmp/save_dir/" ;
275+ bf::path path (save_dir);
276+
277+ if (!bf::exists (path)) {
278+ // 目录不存在,创建
279+ ROS_INFO (" Create %s" , path.c_str ());
280+ bf::create_directory (path);
281+ }
282+
283+ bf::path file_path = path / (std::to_string (timestamp) + " _saveimg" ); // path重载了 / 运算符
284+ bf::create_directory (file_path);
285+
286+
287+ cv::Mat testimg = color_label.clone ();
288+ testimg.setTo (0 );
289+ for (auto &label_map_p: label_map_point) {
290+ if (label_map_p.second .size () < 10 ) continue ;
291+ if (label_map_p.second .size () > 1500 ) continue ;
292+
293+ // get range
294+ cv::Point minp (-1 , -1 ), maxp (-1 , -1 );
295+ for (auto &pp: label_map_p.second ) {
296+ if (minp.x < 0 )minp.x = pp.x ;
297+ if (minp.y < 0 )minp.y = pp.y ;
298+ if (maxp.x < 0 )maxp.x = pp.x ;
299+ if (maxp.x < 0 )maxp.y = pp.y ;
300+
301+ if (minp.x > pp.x ) minp.x = pp.x ;
302+ if (minp.y > pp.y ) minp.y = pp.y ;
303+ if (maxp.x < pp.x ) maxp.x = pp.x ;
304+ if (maxp.y < pp.y ) maxp.y = pp.y ;
305+ }
306+
307+ // draw img
308+
309+ cv::Mat saveimg (maxp.y - minp.y + 10 , maxp.x - minp.x + 10 , CV_8SC1,cv::Scalar (0 ));
310+ for (auto &pp: label_map_p.second ) {
311+ cv::circle (saveimg, cv::Point (pp.x - minp.x , pp.y - minp.y ), 1 , cv::Scalar (255 ));
312+ }
313+
314+ // save
315+ bf::path filename = file_path / bf::path (std::to_string (label_map_p.first ) + " .png" );
316+ cv::imwrite (filename.string (), saveimg);
317+
318+
319+ // cv::imshow("lableImg",testimg);
320+ // cv::waitKey();
321+ }
322+ bf::path filename = file_path / bf::path (std::to_string (timestamp) + " .png" );
323+
324+ cv::imwrite (filename.string (), color_label);
261325
262- cv::imshow (" color_label" ,color_label);
263- cv::waitKey (15 );
264326
265327 // // assign label to pc
266328 if (labelpc == nullptr ) {
0 commit comments