【问题标题】:harris corner points coordinates哈里斯角点坐标
【发布时间】:2015-12-27 21:54:54
【问题描述】:

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

源图片是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);
         }
    } 
}

【问题讨论】:

标签: c++ opencv opencv3.0


【解决方案1】:

您可以将点坐标存储在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&lt;Point&gt; 存储积分可能更直接。在这种情况下,您可以将Svec 声明为:

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

在您的 if 声明中,您将拥有:

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

Svec.emplace_back(i,j);

如果需要,您可以将vector&lt;Point&gt; 转换为Mat,例如:

Mat Z(Svec); // Creates a 2 channels matrix, Nx1
Z = Z.reshape(1); // Creates a 1 channel matrix, Nx2

【讨论】:

  • 垫 pt(1,2,CV_32SC1); pt.at(0, 0) = i; pt.at(0, 1) = j;
【解决方案2】:
Mat pt(1,2,CV_32SC1);
pt.at<int>(0, 0) = i;
pt.at<int>(0, 1) = j;

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

【讨论】:

  • 如果不是 x 和 y 坐标,你认为 i 和 j 是什么?
猜你喜欢
  • 1970-01-01
  • 2016-12-20
  • 1970-01-01
  • 2016-03-16
  • 2014-12-14
  • 1970-01-01
  • 2019-05-30
  • 2020-04-15
  • 1970-01-01
相关资源
最近更新 更多