简体   繁体   English

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

[英]OpenCV: L1 normalization of descriptor matrix

I'm trying to implement SIFTRoot in C++ following this article.我想用C来实现SIFTRoot ++下面这个文章。

In particular:特别是:

    # 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)

My question are:我的问题是:

  1. Is there any built-in C++ function to do this in OpenCV?在 OpenCV 中是否有任何内置的 C++ 函数可以做到这一点?
  2. Are all the descriptors value positive?所有描述符的值都是正的吗? Otherwise the L1 norm should use the abs of each element.否则 L1 范数应该使用每个元素的 abs。
  3. The first line means "for each row vector, compute the sum of all its elements, then add eps (in order to avoid to divide by 0) and finally divide each vector element by this sum value".第一行表示“对于每个行向量,计算其所有元素的总和,然后添加 eps(为了避免除以 0),最后将每个向量元素除以这个总和值”。

The SIFT descriptor is basically a histogram, so it shouldn't have negative values. SIFT 描述符基本上是一个直方图,所以它不应该有负值。 I don't think there exists a single function in OpenCV that does what you want to achieve.我认为 OpenCV 中不存在可以实现您想要实现的功能的单一功能。 But it's not too hard to come up with a few lines that do the job但是想出几行来完成这项工作并不难

// 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);

I don't know exactly how OpenCV deals with zero sum in L1 normalization.我不知道 OpenCV 如何处理 L1 归一化中的零和。 You can replace cv::normalize with descs.rows(i) /= (cv::norm(descs.rows(i), cv::NORM_L1) + eps) if the above code generates NaN.如果上述代码生成 NaN,您可以将cv::normalize替换为descs.rows(i) /= (cv::norm(descs.rows(i), cv::NORM_L1) + eps)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM