哈里斯角点坐标

harris corner points coordinates

我是 opencv 的新手,所以你能帮我找到 harris 使用以下代码检测到的点的坐标吗?

源图像是 img

我想在矩阵中存储角点的坐标S

Mat S;
dst = Mat::zeros( img.size(), CV_32FC1 );
cornerHarris( img, dst, 7, 5, 0.0001, BORDER_DEFAULT );
dst = Mat::zeros( img.size(), CV_32FC1 );
cornerHarris( img, dst, 7, 5, 0.0001, BORDER_DEFAULT );

// Normalizing
normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
convertScaleAbs( dst_norm, dst_norm_scaled );

 for( int j = 0; j < dst_norm.rows ; j++ ) {
     for( int i = 0; i < dst_norm.cols; i++ ) {
         if( (int) dst_norm.at<float>(j,i) > thresh ) {
             S.at<int >(j,i)= (int) dst_norm.at<int>(j,i);
         }
    } 
}

您可以将点坐标存储在 Nx2 矩阵中,其中第一列是 x 坐标,第二列是 y 坐标。

您可以将 S 声明为空 CV_32SC1 矩阵,例如:

Mat S(0, 2, CV_32SC1);

(或者你甚至可以离开 Mat S;,因为类型由第一个 push_back 决定)。

然后您可以附加坐标。在 if 语句中,添加:

// Create a matrix for the point
Mat pt(1,2,CV_32SC1);
pt.at<int>(0, 0) = i;
pt.at<int>(0, 1) = j;

// Add the point to S
S.push_back(pt);

请注意,使用 std::vector<Point> 存储点数会更直接。在这种情况下,您可以将 Svec 声明为:

std::vector<cv::Point> Svec;

并且在您的 if 语句中您将拥有:

Svec.push_back(Point(i,j));

Svec.emplace_back(i,j);

如果需要,您可以将 vector<Point> 转换为 Mat,例如:

Mat Z(Svec); // Creates a 2 channels matrix, Nx1
Z = Z.reshape(1); // Creates a 1 channel matrix, Nx2
Mat pt(1,2,CV_32SC1);
pt.at<int>(0, 0) = i;
pt.at<int>(0, 1) = j;

ij 在您的代码中将是 i,j 计数器的值。 我需要放置哈里斯角点的坐标