我怎么能访问一个高维矩阵的元素在OpenCV
how could I access the element of a high-dimensional matrix in OpenCV?
我试图在OpenCV中使用一个4-d矩阵,初始化部分看起来像这样:
int feature_points_size[] = {bincellDim.x , bincellDim.y , bincellDim.z , 100};
feature_points.create(4 , feature_points_size , CV_64F);
但是库不允许我像这样用'at'访问feature_points的元素:
feature_points.at<double>(k , j , i , l) = stickfea_code.at<double>(l , 0);
feature_points.at<double>(k , j , i , l + 50) = countfea_code.at<double>(l , 0);
似乎Mat.at<>没有4个输入的版本访问它的元素的最佳实践是什么?
提前感谢!
cv::Mat::at<>
确实有n-dim过载,您需要使用T& Mat::at(const int* idx)
版本。
或者,只需为它编写您自己的(外部)包装器,您可以这样使用:
at4D<double>(feature_points,k,j,i,l);
就像@Adi-Shavit的回答:
std::vector<int> dims = {1, 3, 700, 400};
cv::Mat mat4d = cv::Mat(std::vector<int>, CV_32FC1);
int p[4];
p[0] = 0;
for (unsigned hi=0; hi<dims[3]; hi++) {
p[3] = hi;
for (unsigned wi=0; wi<dims[2]; wi++) {
p[2] = wi;
for (unsigned ci=0; ci<dims[1]; ci++) {
p[1] = ci;
float value = mat4d.at<float>(&p[0]);
mat4d.at<float>(&p[0]) = some_new_value;
}
}
}
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 使用strcpy将char数组的元素复制到另一个数组
- 使用不带参数的函数访问结构元素
- 给定n个元素的m个集合.在C++中找到出现在最大集合数中的元素
- C++如何通过用户输入删除列表元素
- lower_bound()返回最后一个元素
- 基于多个条件处理地图中的所有元素
- 调整大小后指向元素值的指针unordered_map有效?
- 使用std::transform将一个范围的元素添加到另一个范围中
- 使用函数"remove"删除重复元素
- 具有最大子序列大小的序列,每个元素都相同
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 如何将元素添加到数组的线程安全函数?
- 有没有办法将谓词中的元素偏移量传递给 std 算法?
- 我想访问std::unique_ptr中的一个特定元素
- 如何通过 getter 函数删除矢量的元素?
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 从控制台中删除最后打印的元素
- 我怎么能访问一个高维矩阵的元素在OpenCV