grid = new int *[grid_rows];
时间: 2024-04-19 22:26:22 浏览: 18
这是在C++中创建一个二维整数数组的代码片段。它使用了`new`关键字来动态分配内存,并创建了一个名为`grid`的指针数组。
首先,它创建了一个指针数组`grid`,这个数组有`grid_rows`个元素。每个元素都是一个指向整数的指针。
然后,通过循环遍历每个数组元素,使用`new`关键字为每个元素分配一个整数数组,这个数组的大小为`grid_cols`。
最终,你将得到一个大小为`grid_rows x grid_cols`的二维整数数组,可以通过`grid[i][j]`来访问和操作其中的元素。记得在不需要使用这个数组时,使用`delete[]`关键字释放内存,以避免内存泄漏。
相关问题
CornerDetector(int n_rows = 8, int n_cols = 10, double detection_threshold = 40.0); ~CornerDetector() = default; void detect_features(const cv::Mat &image, std::vector<cv::Point2f> &features); void set_grid_position(const cv::Point2f &pos); void set_grid_size(int n_rows, int n_cols); int get_n_rows() const { return grid_n_rows_; } int get_n_cols() const { return grid_n_cols_; } float shiTomasiScore(const cv::Mat &img, int u, int v); int sub2ind(const cv::Point2f &sub);
这段代码定义了一个名为 `CornerDetector` 的类,该类具有以下成员函数:
- `CornerDetector(int n_rows = 8, int n_cols = 10, double detection_threshold = 40.0)`:类的构造函数,可以用来初始化占据网格的行数、列数和检测阈值。
- `~CornerDetector() = default`:类的析构函数。
- `void detect_features(const cv::Mat &image, std::vector<cv::Point2f> &features)`:检测输入图像中的角点,并将角点的坐标保存在 `features` 向量中。
- `void set_grid_position(const cv::Point2f &pos)`:设置占据网格的左上角位置。
- `void set_grid_size(int n_rows, int n_cols)`:设置占据网格的行数和列数。
- `int get_n_rows() const { return grid_n_rows_; }`:获取占据网格的行数。
- `int get_n_cols() const { return grid_n_cols_; }`:获取占据网格的列数。
- `float shiTomasiScore(const cv::Mat &img, int u, int v)`:计算图像中指定位置的 Shi-Tomasi 角点得分。
- `int sub2ind(const cv::Point2f &sub)`:将占据网格的行列坐标转换为索引。
for (auto it: nm_corners) { fast::fast_xy &xy = fast_corners.at(it); if (xy.x >= grid_n_cols_ * grid_width_ || xy.y >= grid_n_rows_ * grid_height_) continue; const int k = sub2ind(cv::Point2f(xy.x, xy.y)); if (occupancy_grid_[k]) continue; const float score = shiTomasiScore(image, xy.x, xy.y); if (score > score_table[k]) { score_table[k] = static_cast<double>(score); feature_table[k] = cv::Point2f(xy.x, xy.y); } }
这段代码是在遍历经过非极大值抑制后的角点信息 `nm_corners`,对每个角点进行检查,以确定是否将其作为特征点。对于每个角点,首先获取其坐标,然后判断其是否在图像的有效范围内,如果不在则跳过。接着,将角点的坐标转换为网格的索引,然后检查该网格是否已经被占用(即已经存在特征点)。如果网格已经被占用,则跳过该角点。最后,计算该角点的 Shi-Tomasi 分数,并将分数与该网格之前检测到的所有角点的分数进行比较,如果该角点的分数更高,则将其作为特征点存储在 `feature_table` 向量中,并更新该网格的分数表 `score_table`。经过遍历所有角点后,返回最终的特征点坐标列表 `features`。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)