├── CMakeLists.txt ├── Readme.md ├── View.cpp ├── View.h ├── binFile ├── 47.bin └── 8.bin ├── img ├── example1.png └── example2.png ├── main.cpp ├── object.cpp ├── object.h ├── simpleViewer.cpp ├── simpleViewer.h ├── utils.cpp └── utils.h /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.3) 2 | project(simpleViewer) 3 | add_definitions(-Wall) 4 | 5 | set(CMAKE_CXX_STANDARD 11) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | # if has no defined build set it to Release 10 | if(NOT CMAKE_BUILD_TYPE) 11 | set(CMAKE_BUILD_TYPE Release) 12 | endif() 13 | 14 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -fPIC") 15 | set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") 16 | set(CMAKE_CXX_FLAGS_RELEASE "-O3") 17 | 18 | set(CMAKE_MODULE_PATH 19 | ${CMAKE_MODULE_PATH} 20 | "${PROJECT_SOURCE_DIR}/cmake_modules" 21 | ) 22 | 23 | # Qt5 24 | set(Qt5_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5") 25 | set(Qt5_Widgets "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Widgets") 26 | find_package(Qt5 COMPONENTS Core Widgets Gui Xml OpenGL REQUIRED) 27 | include_directories(${Qt5Core_INCLUDE_DIRS} 28 | ${Qt5Xml_INCLUDE_DIRS} 29 | ${Qt5Gui_INCLUDE_DIRS} 30 | ${Qt5Widgets_INCLUDE_DIRS} 31 | ${Qt5OpenGL_INCLUDE_DIRS}) 32 | 33 | set(MY_QT_LIBRARIES 34 | ${Qt5Widgets_LIBRARIES} 35 | ${Qt5Core_LIBRARIES} 36 | ${Qt5Gui_LIBRARIES} 37 | ${Qt5Xml_LIBRARIES} 38 | ${Qt5OpenGL_LIBRARIES} 39 | ${Boost_LIBRARIES} 40 | /usr/lib/x86_64-linux-gnu/libtiff.so.5 41 | ) 42 | 43 | # for opengl 44 | find_package(OpenGL REQUIRED) 45 | include_directories(${OPENGL_INCLUDE}) 46 | 47 | find_package(QGLViewer REQUIRED) 48 | message(STATUS "Linking against Qt libs: ${MY_QT_LIBRARIES}") 49 | message(STATUS "Linking against QGlViewer lib: ${QGLVIEWER_LIBRARY}") 50 | 51 | ## include 52 | include_directories($CMAKE_CURRENT_SOURCE_DIR) 53 | add_executable(${PROJECT_NAME} main.cpp View.cpp simpleViewer.cpp utils.cpp) 54 | target_link_libraries( 55 | ${PROJECT_NAME} 56 | ${QGLVIEWER_LIBRARY} 57 | ${MY_QT_LIBRARIES} 58 | ${OPENGL_gl_LIBRARY} 59 | ${OPENGL_glu_LIBRARY}) 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | ## Semantic-aware 3D-voxel CenterNet for point cloud object detection 2 | ## All code will be released upon publication of the paper. 3 | ### More detailed results of our SA-voxel-centernet are on the [sa-voxel-centernet](http://www.cvlibs.net/datasets/kitti/eval_object_detail.php?&result=6832bef733b8ae207539e5dbb9d186f572ab8959) 4 | 5 | * src file can get offset as this 6 |

7 | 8 |

9 | -------------------------------------------------------------------------------- /View.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by sj on 2020/5/30. 3 | // 4 | 5 | #include "View.h" 6 | 7 | View::View() 8 | { 9 | // rows_ = 512U; 10 | // cols_ = 512U; 11 | rows_ = 256U; 12 | cols_ = 256U; 13 | resolution_ = rows_ / 80.0F; 14 | range_x_max_ = 80.0f; 15 | range_x_min_ = 0.0f; 16 | range_y_min_ = -40.0f; 17 | range_y_max_ = 40.0f; 18 | voxelPointNum_ = imgInt(rows_, std::vector(cols_, 0)); 19 | voxelProb_ = imgFloat(rows_, std::vector(cols_, 0.0f)); 20 | voxelOffset_ = imgCenter(rows_, std::vector 21 | (cols_, utils::point2d(0.0f, 0.0f))); 22 | voxelCenter_ = imgCenter(rows_, std::vector 23 | (cols_, utils::point2d(0.0f, 0.0f))); 24 | } 25 | 26 | void View::Build(const std::vector& input) { 27 | for(size_t dataIdx = 0; dataIdx < input.size(); ++dataIdx) 28 | { 29 | const utils::data& da = input[dataIdx]; 30 | int row; 31 | int col; 32 | Project(da, row, col); 33 | size_t debug = 1U; 34 | ++voxelPointNum_[row][col]; 35 | if (voxelProb_[row][col] < da.cls) { 36 | voxelProb_[row][col] = da.cls; 37 | voxelOffset_[row][col] = utils::point2d((da.x - da.reg[0]), (da.y - da.reg[1])); 38 | } 39 | } 40 | for (int row = 0; row < rows_; ++row) { 41 | for (int col = 0; col < cols_; ++col) 42 | { 43 | voxelCenter_[row][col] = utils::point2d((range_x_max_ - static_cast(row) / resolution_ - 0.5f / resolution_), 44 | (range_y_max_ - static_cast(col) / resolution_ - 0.5f / resolution_)); 45 | } 46 | } 47 | std::cout << "View::build finished..." << std::endl; 48 | } 49 | 50 | void View::Project(const utils::data& da, int& row, int& col) 51 | { 52 | row = floor((-da.x + range_x_max_) * resolution_); 53 | col = floor((-da.y + range_y_max_) * resolution_); 54 | } 55 | 56 | void View::Project(const utils::point2d& input, int& row, int& col) 57 | { 58 | printf("input ==> [%f, %f]\n", input.x, input.y); 59 | row = floor((-input.x + range_x_max_) * resolution_); 60 | col = floor((-input.y + range_y_max_) * resolution_); 61 | row = std::min(row, int(rows_ - 1)); 62 | col = std::min(col, int(cols_ - 1)); 63 | printf("input ==> [%d, %d]\n", row, col); 64 | } -------------------------------------------------------------------------------- /View.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by sj on 2020/5/30. 3 | // 4 | 5 | #ifndef SIMPLEVIEWER_VIEW_H 6 | #define SIMPLEVIEWER_VIEW_H 7 | 8 | #include 9 | #include 10 | #include "utils.h" 11 | #include 12 | #include "object.h" 13 | 14 | typedef std::vector> imgFloat; 15 | typedef std::vector> imgInt; 16 | typedef std::vector> imgCenter; 17 | 18 | class View { 19 | public: 20 | View(); 21 | View(const std::vector& input); 22 | void Build(const std::vector& input); 23 | void Project(const utils::data& da, int& row, int& col); 24 | void Project(const utils::point2d& input, int& row, int& col); 25 | int Count(const int& row, const int& col) {return voxelPointNum_[row][col];} 26 | int GetProb(const int& row, const int& col) {return voxelProb_[row][col];} 27 | utils::point2d GetCenter(const int& row, const int& col){return voxelCenter_[row][col];}; 28 | utils::point2d GetOffset(const int& row, const int& col){return voxelOffset_[row][col];}; 29 | 30 | const size_t rows() const {return rows_;}; 31 | const size_t cols() const {return cols_;}; 32 | 33 | private: 34 | size_t rows_; 35 | size_t cols_; 36 | float range_x_max_; 37 | float range_x_min_; 38 | float range_y_max_; 39 | float range_y_min_; 40 | float resolution_; 41 | imgInt voxelPointNum_; 42 | imgFloat voxelProb_; 43 | imgCenter voxelOffset_; 44 | imgCenter voxelCenter_; 45 | imgFloat voxel; 46 | 47 | }; 48 | 49 | 50 | #endif //SIMPLEVIEWER_VIEW_H 51 | -------------------------------------------------------------------------------- /binFile/47.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunjingnjupt/sa-voxel-centernet/75743f9358e56581be82f659f17854c63f64333e/binFile/47.bin -------------------------------------------------------------------------------- /binFile/8.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunjingnjupt/sa-voxel-centernet/75743f9358e56581be82f659f17854c63f64333e/binFile/8.bin -------------------------------------------------------------------------------- /img/example1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunjingnjupt/sa-voxel-centernet/75743f9358e56581be82f659f17854c63f64333e/img/example1.png -------------------------------------------------------------------------------- /img/example2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sunjingnjupt/sa-voxel-centernet/75743f9358e56581be82f659f17854c63f64333e/img/example2.png -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "simpleViewer.h" 2 | #include 3 | 4 | int main(int argc, char **argv) { 5 | // Read command lines arguments. 6 | QApplication application(argc, argv); 7 | 8 | // Instantiate the viewer. 9 | Viewer viewer; 10 | 11 | viewer.setWindowTitle("simpleViewer"); 12 | 13 | // Make the viewer window visible on screen. 14 | viewer.show(); 15 | 16 | // Run main loop. 17 | return application.exec(); 18 | } -------------------------------------------------------------------------------- /object.cpp: -------------------------------------------------------------------------------- 1 | #include "object.h" 2 | #include 3 | 4 | using namespace qglviewer; 5 | 6 | void Object::draw() const { 7 | // glPushMatrix(); 8 | // glMultMatrixd(frame.matrix()); 9 | // glRectf(-0.01f, -0.01f, 0.01f, 0.01f); 10 | // glPopMatrix(); 11 | 12 | 13 | // glPushMatrix(); 14 | // glPointSize(2); 15 | // glBegin(GL_POINT); 16 | // // glBegin(GL_POINTS); 17 | // glMultMatrixd(frame.matrix()); 18 | // glVertex3f(0.0, 0.0,0.0); 19 | // // glRectf(-0.01f, -0.01f, 0.01f, 0.01f); 20 | // glEnd(); 21 | // glPopMatrix(); 22 | 23 | static GLUquadric *quad = gluNewQuadric(); 24 | glPushMatrix(); 25 | glMultMatrixd(frame.matrix()); 26 | glBegin(GL_POINTS); 27 | glVertex3d(0.0, 0.0, 0.0); 28 | glEnd(); 29 | glPopMatrix(); 30 | } -------------------------------------------------------------------------------- /object.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_H_ 2 | #define OBJECT_H_ 3 | 4 | #include "QGLViewer/frame.h" 5 | #include 6 | class Object { 7 | public: 8 | using Ptr = std::shared_ptr; 9 | explicit Object(){} 10 | void draw() const; 11 | qglviewer::Frame frame; 12 | }; 13 | 14 | #endif // OBJECT_H_ -------------------------------------------------------------------------------- /simpleViewer.cpp: -------------------------------------------------------------------------------- 1 | #include "simpleViewer.h" 2 | 3 | using namespace std; 4 | // Draws a spiral 5 | 6 | void Viewer::draw2() { 7 | glDisable(GL_DEPTH_TEST); 8 | glDisable(GL_LIGHTING); 9 | qglColor(Qt::black); 10 | glPushMatrix(); 11 | fprintf(stderr, "[INFO] show ing.....\n"); 12 | utils::data* tmpData = offsets_.data(); 13 | // draw origin points 14 | glPointSize(2.0f); 15 | glColor3f(1.0f, 1.0f, 1.0f); 16 | glBegin(GL_POINTS); 17 | tmpData = offsets_.data(); 18 | for (int idx = 0; idx < offsets_.size(); ++idx) { 19 | float cls = tmpData->cls; 20 | glVertex3f(tmpData->x, tmpData->y, tmpData->z); 21 | tmpData += 1; 22 | } 23 | glEnd(); 24 | glPopMatrix(); 25 | 26 | glPointSize(1.0f); 27 | float x, y, z; 28 | glBegin(GL_LINES); 29 | tmpData = offsets_.data(); 30 | glColor3f(0.835f, 0.031f, 0.043f); // 浅红色 31 | for (int idx = 0; idx < offsets_.size(); ++idx) { 32 | x = tmpData->x - tmpData->reg[0]; 33 | y = tmpData->y - tmpData->reg[1]; 34 | z = tmpData->z - tmpData->reg[2]; 35 | float cls = tmpData->cls; 36 | if (cls > 0.3f) { 37 | glVertex3f(tmpData->x, tmpData->y, tmpData->z); 38 | glVertex3f(x, y, z); 39 | } 40 | tmpData += 1; 41 | } 42 | glEnd(); 43 | 44 | // draw center points 45 | glPointSize(1.2f); 46 | glColor3f(0.0f, 1.0f, 0.0f); // 47 | glBegin(GL_POINTS); 48 | tmpData = offsets_.data(); 49 | for (int idx = 0; idx < offsets_.size(); ++idx) { 50 | x = tmpData->x - tmpData->reg[0]; 51 | y = tmpData->y - tmpData->reg[1]; 52 | z = tmpData->z - tmpData->reg[2]; 53 | float cls = tmpData->cls; 54 | if (cls > 0.3f) { 55 | glVertex3f(x, y, z); 56 | } 57 | tmpData += 1; 58 | } 59 | glEnd(); 60 | // draw origin points 61 | glPointSize(3.0f); 62 | glColor3f(0.0f, 0.0f, 1.0f); 63 | glBegin(GL_POINTS); 64 | tmpData = offsets_.data(); 65 | for (int idx = 0; idx < offsets_.size(); ++idx) { 66 | float cls = tmpData->cls; 67 | if (cls > 0.3f) { 68 | glVertex3f(tmpData->x, tmpData->y, tmpData->z); 69 | } 70 | tmpData += 1; 71 | } 72 | glEnd(); 73 | glPopMatrix(); 74 | glFlush(); 75 | } 76 | 77 | void Viewer::draw() { 78 | glDisable(GL_DEPTH_TEST); 79 | glDisable(GL_LIGHTING); 80 | qglColor(Qt::black); 81 | glPushMatrix(); 82 | fprintf(stderr, "[INFO] show ing.....\n"); 83 | // show voxel point with prob_ 84 | // draw origin points 85 | glPointSize(3.0f); 86 | glColor3f(1.0f, 1.0f, 1.0f); 87 | glBegin(GL_POINTS); 88 | utils::data* tmpData = offsets_.data(); 89 | for (int idx = 0; idx < offsets_.size(); ++idx) { 90 | float cls = tmpData->cls; 91 | // if (cls > 0.3f) { 92 | glVertex3f(tmpData->x, tmpData->y, 0.0); 93 | // } 94 | tmpData += 1; 95 | } 96 | glEnd(); 97 | 98 | glPointSize(2.5f); 99 | glBegin(GL_POINTS); 100 | for (int row = 0; row < view_.rows(); ++row) { 101 | for (int col = 0; col < view_.cols(); ++col) { 102 | // int numVoxelPts = view_.Count(row, col); 103 | float prob = view_.GetProb(row, col); 104 | // if (numVoxelPts > 0) { 105 | if (prob > confidence_min_threshold_) { 106 | const float& prob = view_.GetProb(row, col); 107 | // glColor3f(prob, prob, prob); 108 | glColor3f(1.0f, 1.0f, 1.0f); 109 | utils::point2d center2d = view_.GetCenter(row, col); 110 | glVertex3f(center2d.x, center2d.y, 0.0f); 111 | } 112 | } 113 | } 114 | glEnd(); 115 | // draw node 116 | // glBegin(GL_LINES); 117 | // for (int row = 0; row < rows_; ++row) { 118 | // for (int col = 0; col < cols_; ++col) { 119 | // Node* node = &nodes_[row][col]; 120 | //// if (view_.Count(node->row, node->col) == 0 || 121 | //// view_.GetProb(node->row, node->col) < confidence_min_threshold_) { 122 | //// continue; 123 | //// } 124 | // // Node* root_node = utils::FindRootNode(node); 125 | // Node* root_node = node->parent; 126 | // utils::point2d nodePt = view_.GetCenter(node->row, node->col); 127 | // utils::point2d rootNodePt = view_.GetCenter(root_node->row, root_node->col); 128 | // glColor3f(1.0f, 0.0f, 0.0f); 129 | // glVertex3f(nodePt.x, nodePt.y, 0.0f); 130 | // glColor3f(0.0f, 1.0f, 0.0f); 131 | // glVertex3f(rootNodePt.x, rootNodePt.y, 0.0f); 132 | //// printf("[%d][%d] (%f, %f) ==> (%f, %f)\n", 133 | //// node->row, node->col, nodePt.x, nodePt.y, rootNodePt.x, rootNodePt.y); 134 | // } 135 | // } 136 | // glEnd(); 137 | 138 | // draw offset 139 | glBegin(GL_LINES); 140 | glColor3f(1.0f, 0.0f, 0.0f); 141 | for (int row = 0; row < view_.rows(); ++row) 142 | { 143 | for (int col = 0; col < view_.cols(); ++col) { 144 | int numVoxelPts = view_.Count(row, col); 145 | if (numVoxelPts > 0) { 146 | const float& prob = view_.GetProb(row, col); 147 | if (prob > confidence_min_threshold_) { 148 | utils::point2d center2d = view_.GetCenter(row, col); 149 | glVertex3f(center2d.x, center2d.y, 0.0f); 150 | utils::point2d offset2d = view_.GetOffset(row, col); 151 | glVertex3f(offset2d.x, offset2d.y, 0.0f); 152 | } 153 | } 154 | } 155 | } 156 | glEnd(); 157 | glPopMatrix(); 158 | // draw Segment center 159 | glPointSize(1.2f); 160 | glColor3f(0.0f, 1.0f, 0.0f); 161 | int count = 0; 162 | for (int row = 0; row < rows_; ++row){ 163 | for (int col = 0; col < cols_; ++col) { 164 | Node* node = &nodes_[row][col]; 165 | if (gridVotes_[node->row][node->col]) { 166 | glPushMatrix(); 167 | utils::point2d seg_center = view_.GetCenter(row, col); 168 | glTranslatef(seg_center.x, seg_center.y, 0.0f); 169 | drawCircle(0.08, 12); 170 | glPopMatrix(); 171 | ++count; 172 | } 173 | } 174 | } 175 | std::cout << "count: " << count << std::endl; 176 | // end of draw Segment 177 | glFlush(); 178 | } 179 | 180 | void Viewer::drawCircle(const float & radius, const int & numPoints) const 181 | { 182 | // glVertex2f(R*cos(2*Pi/n*i), R*sin(2*Pi/n*i)); 183 | // glBegin(GL_LINE_STRIP); 184 | // solid circle 185 | glBegin(GL_TRIANGLE_FAN); 186 | for (size_t idx = 0; idx < numPoints; ++idx) 187 | { 188 | glVertex3f(radius * cos(2 * M_PI / numPoints * idx), radius * sin(2 * M_PI / numPoints * idx), 0.0f); 189 | } 190 | glVertex3f(radius * cos(0), radius * sin(0), 0); 191 | glEnd(); 192 | } 193 | 194 | void Viewer::init() { 195 | // Restore previous viewer state. 196 | glClear(GL_COLOR_BUFFER_BIT); 197 | setBackgroundColor(QColor(1, 0, 1)); 198 | offsets_ = utils::ReadKittiBinByPath(binFileName_); 199 | // PrintOffsets(); 200 | // 下面俩行, 一定要加, 不要会有阴影显示 201 | setSceneRadius(50); 202 | camera()->showEntireScene(); 203 | objects.clear(); 204 | view_.Build(offsets_); 205 | // restoreStateFromFile(); 206 | find_all_node(); 207 | find_all_node2(); 208 | } 209 | 210 | void Viewer::find_all_node2() 211 | { 212 | imgBool grid_skips(view_.rows(), std::vector(view_.cols(), true)); 213 | // init whole nodes 214 | for (int row = 0; row < view_.rows(); ++row) { 215 | for (int col = 0; col < view_.cols(); ++col) { 216 | nodes_[row][col].parent = &nodes_[row][col]; 217 | nodes_[row][col].row = row; 218 | nodes_[row][col].col = col; 219 | } 220 | } 221 | for (int row = 0; row < view_.rows(); ++row) { 222 | for (int col = 0; col < view_.cols(); ++col) { 223 | grid_skips[row][col] = view_.Count(row, col) == 0 || 224 | view_.GetProb(row, col) < confidence_min_threshold_; 225 | // get offset position float 226 | utils::point2d center_estimate = view_.GetOffset(row, col); 227 | int center_row; 228 | int center_col; 229 | if (grid_skips[row][col]) { 230 | continue; 231 | } 232 | view_.Project(center_estimate, center_row, center_col); 233 | // let current node parent to be the offset parent 234 | nodes_[row][col].parent = &nodes_[center_row][center_col]; 235 | 236 | // printf("node[%d][%d] ===> nodes_[%d][%d]\n", 237 | // nodes_[row][col].row, nodes_[row][col].col, 238 | // nodes_[center_row][center_col].row, 239 | // nodes_[center_row][center_col].col); 240 | } 241 | } 242 | for (int row = 0; row < view_.rows(); ++row) { 243 | for (int col = 0; col < view_.cols(); ++col) { 244 | if (!grid_skips[row][col]) { 245 | auto root_node = nodes_[row][col].parent; 246 | ++gridVotes_[root_node->row][root_node->col]; 247 | } 248 | } 249 | } 250 | } 251 | 252 | void Viewer::find_all_node() 253 | { 254 | 255 | } 256 | 257 | void Viewer::find_all_node_parent_record(Node* x, std::vector& path) 258 | { 259 | 260 | } 261 | 262 | void Viewer::PrintOffsets() 263 | { 264 | for (int idx = 0; idx < offsets_.size(); ++idx) { 265 | fprintf(stderr, "%f %f %f %f %f %f %f %f\n", offsets_[idx].batchIdx, offsets_[idx].x, 266 | offsets_[idx].y, offsets_[idx].z, offsets_[idx].cls, offsets_[idx].reg); 267 | } 268 | fprintf(stderr, "[INFO] data shape is [%d, %d]\n", offsets_.size(), 8); 269 | } 270 | 271 | -------------------------------------------------------------------------------- /simpleViewer.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "utils.h" 5 | #include "View.h" 6 | #include 7 | #include "object.h" 8 | 9 | class Node{ 10 | public: 11 | Node* parent = nullptr; 12 | // been visted, 0 not visted, -1 has visted, 1 has visted condition 2, loop condition?? 13 | int visted = 0; 14 | // true has find center node, false not find center node 15 | bool is_root_center = false; 16 | int level = 0; // center has hight level, first level is zeros 17 | int row = 0; 18 | int col = 0; 19 | int seg_id = -1; 20 | }; 21 | 22 | class Segment 23 | { 24 | public: 25 | Segment() {}; 26 | Segment(int input_seg_id):seg_id(input_seg_id) {} 27 | int seg_id = -1; 28 | }; 29 | 30 | typedef std::vector> imgNode; 31 | typedef std::vector> imgNodePtr; 32 | typedef std::vector> imgBool; 33 | class Viewer : public QGLViewer { 34 | protected: 35 | virtual void draw(); 36 | virtual void init(); 37 | void find_all_node(); 38 | void find_all_node2(); 39 | void find_all_node_parent_record(Node* x, std::vector& path); 40 | void draw2(); 41 | void drawCircle(const float & radius, const int & numPoints) const; 42 | 43 | public: 44 | std::vector objects; 45 | 46 | private: 47 | std::string binFileName_ = "../binFile/47.bin"; 48 | // std::string binFileName_ = "./binFile/8.bin"; 49 | std::vector offsets_; 50 | View view_; 51 | 52 | // cluster center relative 53 | private: 54 | // size_t rows_ = 512U; 55 | // size_t cols_ = 512U; 56 | size_t rows_ = 256U; 57 | size_t cols_ = 256U; 58 | imgNode nodes_ = imgNode(rows_, std::vector(cols_, Node())); 59 | imgInt gridVotes_ = imgInt(view_.rows(), std::vector(view_.cols(), 0)); 60 | std::vector segments_; 61 | float confidence_min_threshold_ = 0.3f; 62 | float blocking_threshold_ = 0.3f; 63 | imgBool grid_sklip_; 64 | 65 | private: 66 | void PrintOffsets(); 67 | }; 68 | -------------------------------------------------------------------------------- /utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | namespace utils 3 | { 4 | std::vector ReadKittiBinByPath(const std::string & path) 5 | { 6 | fprintf(stderr, "[INFO] start read bin file\n"); 7 | std::vector offsets; 8 | utils::data* dataVec = offsets.data(); 9 | std::fstream file(path.c_str(), std::ios::in | std::ios::binary); 10 | if (file.good()) 11 | { 12 | fprintf(stderr, "[INFO] file %s is good\n", path.c_str()); 13 | file.seekg(0, std::ios::beg); 14 | utils::data tmpData; 15 | for (int i = 0; file.good() && !file.eof(); ++i) 16 | { 17 | file.read(reinterpret_cast(&tmpData), sizeof(utils::data)); 18 | offsets.emplace_back(tmpData); 19 | } 20 | file.close(); 21 | } 22 | return offsets; 23 | fprintf(stderr, "[INFO] end read bin file\n"); 24 | } 25 | }; -------------------------------------------------------------------------------- /utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace utils{ 9 | struct data { 10 | float batchIdx = 0.0f; 11 | float x = 0.0f; 12 | float y = 0.0f; 13 | float z = 0.0f; 14 | float cls = 0.0f; 15 | float reg[3]; 16 | }; 17 | 18 | struct point{ 19 | float x = 0.0f; 20 | float y = 0.0f; 21 | float z = 0.0f; 22 | }; 23 | 24 | struct point2d{ 25 | float x = 0.0f; 26 | float y = 0.0f; 27 | public: 28 | point2d(const float& x_i, const float& y_i):x(x_i), y(y_i) {} 29 | }; 30 | std::vector ReadKittiBinByPath(const std::string & path); 31 | 32 | template 33 | T* FindRootNode(T* p1, T* p2) 34 | { 35 | if (p1->parent != p2) { 36 | p1->parent = FindRootNode(p1->parent, p2->parent); 37 | } 38 | return p1->parent; 39 | } 40 | 41 | template 42 | T* FindRootNode(T* p) 43 | { 44 | T* nodeTmp = p->parent; 45 | if (p->parent == nodeTmp) { 46 | return nodeTmp; 47 | } 48 | T* root = FindRootNode(p, p->parent); 49 | p->parent = root; 50 | p->parent = root; 51 | return root; 52 | } 53 | 54 | template 55 | void JointUnionNode(T* node1, T* node2) 56 | { 57 | node1 = FindRootNode(node1); 58 | node2 = FindRootNode(node2); 59 | if (node1 == node2) { 60 | return; 61 | } 62 | if (node1->level < node2->level) { 63 | node1->parent = node2; 64 | } else if(node2->level < node1->level) { 65 | node2->parent = node1; 66 | } else { 67 | node1->parent = node2; 68 | node2->level++; 69 | } 70 | } 71 | }; 72 | #endif --------------------------------------------------------------------------------