简体   繁体   English

Opencv C ++中的Harris Corner Detector中的规范化?

[英]Normalization in Harris Corner Detector in Opencv C++?

I was reading the documentation on finding corners in an image using the Harris Corner detector. 我正在阅读有关使用Harris角检测器在图像中找到角的文档。 I couldn't understand why they normalized the image after applying the Harris Corner function. 我不明白他们为什么在应用Harris Corner函数后将图像标准化。 I am a bit confused about the idea of normalization. 我对规范化的概念有些困惑。 Can someone explain me why do we normalize an image? 有人可以向我解释为什么我们要对图像进行归一化吗? Also, what does convertscaleabs() do. 另外,convertscaleabs()的作用是什么。 I am still a starter in opencv and so its kind of hard to understand from the documentation. 我仍然是opencv的入门者,因此很难从文档中了解它。

cornerHarris( src_gray, dst, blockSize, apertureSize, k, BORDER_DEFAULT );

  /// Normalizing
  normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() ); //(I couldnot understand this line)
  convertScaleAbs( dst_norm, dst_norm_scaled ); // ???

Thanks 谢谢

I recommend you get familiar with image processing fundamentals before diving into OpenCV. 我建议您在进入OpenCV之前先熟悉图像处理基础知识。 Having a solid notion of basic concepts like contrast, binarization, clipping, threshold, slice, histogram, etc. (just to mention a few) will make your journey through OpenCV easier. 对比度,二值化,裁剪,阈值,切片,直方图等基本概念有扎实的概念(仅举几例),将使您通过OpenCV的旅程更加轻松。

That said, Wikipedia defines it like this: "Normalization is a process that changes the range of pixel intensity values... Normalization is sometimes called contrast stretching or histogram stretching". 也就是说,Wikipedia的定义如下:“规范化是更改像素强度值范围的过程……规范化有时称为对比度拉伸或直方图拉伸”。

To illustrate this definition I will try to give you a simple example: 为了说明这个定义,我将尝试给你一个简单的例子:

Imagine you have an 8 bit gray scale image, possible pixel intensity values go from 0 to 255. If the image has "low contrast", its histogram will show a concentration of pixels around a certain value like you can see in the following picture: 假设您有一个8位灰度图像,可能的像素强度值从0到255。如果图像具有“低对比度”,则其直方图将在一定值附近显示像素浓度,如下图所示:

直方图

Now what normalization does is to "take" this histogram and stretch it. 现在,归一化的作用是“获取”此直方图并将其拉伸 It applies an intensity transformation map that correlates the original minimum and maximum intensity values with a new pair of minimum and maximum values within the full range of intensities (0 to 255). 它应用强度转换贴图,该贴图将原始的最小和最大强度值与整个强度范围(0到255)内的一对新的最小和最大值相关。

As for convertScaleAbs() the documentation says that it scales, calculates absolute values, and converts the result to 8-bit . 至于convertScaleAbs() ,文档说它可以缩放,计算绝对值,并将结果转换为8位 Not much more to say about it. 没有更多关于它的说法。

Full prototype is void convertScaleAbs(InputArray src, OutputArray dst, double alpha=1, double beta=0) , so used like that it will just calculate the absolute value of each element in the matrix and convert it to a valid 8-bit unsigned value. 完整的原型为void convertScaleAbs(InputArray src, OutputArray dst, double alpha=1, double beta=0) ,因此使用该方法只是将计算矩阵中每个元素的绝对值并将其转换为有效的8位无符号值。

You're probably looking at the code of the OpenCV tutorials . 您可能正在看OpenCV教程的代码。

By normalizing the corner response (that are in some unknown interval) in the interval [0, 255] with 通过归一化间隔[0,255]中的转角响应(在某个未知间隔中)

normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );

it's easier to select a threshold (since you now know the the threshold will also be in the interval [0, 255]) to keep only strongest responses. 选择一个阈值比较容易(因为您现在知道阈值也将在[0,255]区间内)以仅保留最强的响应。 The range [0,255] is useful when, such in this case, you get the threshold value through a slider, which can have only integer values. 例如,在这种情况下,通过滑块可以获取阈值时,范围[0,255]很有用,该滑块只能具有整数值。

convertScaleAbs(dst_norm, dst_norm_scaled);

is needed only to convert dst_norm to a Mat of type CV_8U , so it can be shown correctly by imshow . 只需要转换dst_normMat类型的CV_8U ,所以它可以正确地显示imshow

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

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