我正在使用霍夫变换算法确定行。 现在,我只是从矩阵中获取超过某个阈值的峰值,但是我得到了很多重复的行,我想将它们合并成一个行。
这是查找峰的代码:
int prevVal = INT_MIN;
const int NOISE = 110;
enum
{
Ascending,
Descending
} direction = Ascending;
std::vector<Peak>peaks;
for (int x = 0; x < m_matrixWidth - 1; x++) {
for (int y = 0; y < m_matrixHeight - 1; y++) {
double currentValue = m_matrix[x*m_matrixHeight + y];
if (prevVal < currentValue) {
direction = Ascending;
}
else if (prevVal > currentValue) {
if (direction != Descending) {
if (currentValue > NOISE) {
Peak peak(x, y, currentValue);
peaks.push_back(peak);
std::cout << "peak at index " << x*m_matrixHeight + y << ": " << prevVal << std::endl;
}
direction = Descending;
}
}
prevVal = currentValue;
}
}
return peaks;
如果有人知道,谢谢。