我有一个类型cv::Mat xyz
的矩阵CV_32FC3
,用于存储图像的三维坐标。我要根据某个条件检查每个z
坐标。我尝试了一个指向一行的指针,然后遍历cols,但某处是一个错误,因为我想得到错误的值,只要我想要评估指针。 (不要混淆vector<Point> pts
,我只需要在向量中存储相应的位置。这里我的代码:
const int rows = xyz.rows;
const int cols = xyz.cols;
for (int row = 0; row < rows; ++row) {
uchar* p_3d = _xyz.ptr(row);//Take a pointer to j-th row of the image to be drawn
for (int col = 0; col < cols; ++col) {
//Check z channel being valid
if(p_3d[2] != -1) {
pts.push_back(Point(col,row));
}
p_3d += 3;
}
}
有人看到我的错误吗? 如何正确使用指向行的指针?