Skip to content

Commit cfc03f0

Browse files
committed
save clustering image
1 parent 39594bb commit cfc03f0

5 files changed

Lines changed: 89 additions & 14 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ catkin_package(CATKIN_DEPENDS
2424
)
2525

2626
add_definitions(-std=c++11)
27-
SET(CMAKE_CXX_FLAGS "-O2 -g -Wall ${CMAKE_CXX_FLAGS}")
27+
SET(CMAKE_CXX_FLAGS "-O3 -g -Wall ${CMAKE_CXX_FLAGS}")
2828

2929
#set(OpenCV_DIR "/usr/local/share/OpenCV")
3030

include/aggregation.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,32 @@ namespace LaneDetect {
1919
countimg = cv::Mat(IMAGE_HEIGHT, IMAGE_WIDTH, CV_32SC1);
2020
imgzmin = cv::Mat(IMAGE_HEIGHT, IMAGE_WIDTH, CV_32SC1);
2121
imgzmax= cv::Mat(IMAGE_HEIGHT, IMAGE_WIDTH, CV_32SC1);
22+
23+
save_labelimg_ = true;
24+
labelimg_empty_ = true;
25+
26+
if(save_labelimg_){
27+
28+
// std::
29+
}
2230
};
2331

2432
void Process(const std::deque<Frame> &data_buffer, const Eigen::Matrix4f &world_imu, const Eigen::Matrix4f &imu_vel,
25-
int frame_size, pcl::PointCloud<PPoint>::Ptr &pc, pcl::PointCloud<PPoint>::Ptr& labelpc);
33+
int frame_size, pcl::PointCloud<PPoint>::Ptr &pc, pcl::PointCloud<PPoint>::Ptr& labelpc, uint64_t timestamp);
2634

2735
void ToPclPc(pcl::PointCloud<PPoint>::Ptr &pc, pcl::PointCloud<pcl::PointXYZ>::Ptr &pclpc);
2836

37+
static void SaveLabelImg(std::map<int, std::vector<cv::Point>> &label_map_point);
38+
2939
private:
3040
cv::Mat img; //(IMAGE_HEIGHT, IMAGE_WIDTH, CV_8UC1);
3141
cv::Mat avgimg; //(IMAGE_HEIGHT, IMAGE_WIDTH, CV_32FC1);
3242
cv::Mat countimg; //(IMAGE_HEIGHT, IMAGE_WIDTH, CV_32SC1);
3343
cv::Mat imgzmin; //(IMAGE_HEIGHT, IMAGE_WIDTH, CV_32SC1);
3444
cv::Mat imgzmax; //(IMAGE_HEIGHT, IMAGE_WIDTH, CV_32SC1);
3545

46+
bool save_labelimg_;
47+
bool labelimg_empty_;
3648
};
3749

3850
}

include/utils/common.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
namespace LaneDetect {
1818

19-
const int IMAGE_HEIGHT = 600;
20-
const int IMAGE_WIDTH = 2000;
21-
const float RES_STEP = 0.08;
19+
const int IMAGE_HEIGHT = 900;
20+
const int IMAGE_WIDTH = 3000;
21+
const float RES_STEP = 0.04;//0.08
2222

2323
const float EPS = 1e-6;
2424

main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace LaneDetect {
6565
const geometry_msgs::PoseStampedConstPtr &imu_msg);
6666
};
6767

68-
DetectManager::DetectManager() : node_handle_("~"), lidar_size_(20) {
68+
DetectManager::DetectManager() : node_handle_("~"), lidar_size_(30) {
6969
ROS_INFO("Inititalizing BucketFiltering node ...");
7070
node_handle_.param<std::string>("point_topic", point_topic_, "/velodyne_points");
7171
ROS_INFO("Input Point Cloud: %s", point_topic_.c_str());
@@ -177,7 +177,8 @@ namespace LaneDetect {
177177

178178
pcl::PointCloud<PPoint>::Ptr out_pc(new pcl::PointCloud<PPoint>());
179179
pcl::PointCloud<PPoint>::Ptr out_labelpc(new pcl::PointCloud<PPoint>());
180-
aggregation_.Process(data_buffer_, world_imu_, imu_vel_, 20, out_pc, out_labelpc);
180+
aggregation_.Process(data_buffer_, world_imu_, imu_vel_, 20, out_pc, out_labelpc,
181+
in_cloud_msg->header.stamp.toNSec());
181182

182183
out_pc->header = c_in_cloud->header;
183184
out_labelpc->header = c_in_cloud->header;

src/aggregation.cc

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
#include "cca.cc"
1212
#include <map>
1313

14+
#include<boost/filesystem.hpp>
15+
1416
#include <assert.h>
1517
namespace LaneDetect {
18+
namespace bf=boost::filesystem;//简单别名
19+
1620

1721
void 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

Comments
 (0)