python - OpenCV:描述符矩阵的L1归一化

标签 python c++ opencv normalization norm

我正在尝试在 this 之后用 C++ 实现 SIFTRoot文章。

特别是:

    # apply the Hellinger kernel by first L1-normalizing and taking the
    # square-root
    descs /= (descs.sum(axis=1, keepdims=True) + eps)
    descs = np.sqrt(descs)

我的问题是:

  1. OpenCV 中是否有任何内置的 C++ 函数可以执行此操作?
  2. 所有的描述符都是正值吗?否则 L1 范数应该使用每个元素的绝对值。
  3. 第一行的意思是“对于每个行 vector ,计算其所有元素的总和,然后加上eps(为了避免除以0)最后将每个 vector 元素除以这个总和值”。

最佳答案

SIFT 描述符基本上是一个直方图,因此它不应该有负值。我认为 OpenCV 中没有一个函数可以实现您想要实现的目标。但是想出几行来完成这项工作并不难

// For each row
for (int i = 0; i < descs.rows; ++i) {
  // Perform L1 normalization
  cv::normalize(descs.row(i), descs.row(i), 1.0, 0.0, cv::NORM_L1);
}
// Perform sqrt on the whole descriptor matrix
cv::sqrt(descs, descs);

我不确切知道 OpenCV 如何处理 L1 归一化中的零和。您可以将 cv::normalize 替换为 descs.rows(i)/= (cv::norm(descs.rows(i), cv::NORM_L1) + eps) 如果上面的代码生成 NaN。

关于python - OpenCV:描述符矩阵的L1归一化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38517401/

相关文章:

c++ - 在 OpenCV 上组织 channel

c++ - 使用 OpenCV 导出颜色校正矩阵

python - OpenCV 错误 : Unspecified Error(The Function is not implemented)

python 属性错误 : 'tuple' object has no attribute 'show' using matplotlib

python - python中字母前的下划线(_p)是什么意思

c++ - 柯南如何帮助 CMake 找到 DLL 的位置?

c++ - C++ 中的 concurrent_unordered_map

python - Tensorflow - ops 构造函数是什么意思?

python - 在 Keras 中将 LSTM 与具有不同张量维度的 CNN 连接起来

python - 如何使终端中的 vscode 调试不那么冗长?