运算符0和1在OpenCV的MorphologyEx()函数中做了什么 [英] What does the Operator 0 and 1 do in MorphologyEx() function of OpenCV
问题描述
大家好,
我正在使用OpenCV的MorphologyEx()函数编写代码,当我错误地将值0赋给函数的'Morphology Operator'参数时。
可以在功能规格中看到 [运营商值范围 ^ ]从2-6分别开始,关闭,渐变,顶部,底部操作。
该函数应该给运算符值0一些错误,但它工作正常,我收到的结果就像一个更强大的Closing过滤器。这个结果对我的项目有利,但我想知道它是什么过滤器。该函数还给出了一些操作符参数设置为1的结果。
如果有人知道运算符值0和1的作用,请告诉我。
Hello all,
I was writing a code with MorphologyEx() function of OpenCV, when i mistakenly gave value 0 to 'Morphology Operator' parameter of the function.
As can be seen in the function specs [^], the Operator value ranges from 2-6 for Opening, Closing, Gradient, Top, Bottom hat operations respectively.
The function should ve given some error with Operator value 0, but it worked fine, and the results i received were like a stronger Closing filter. This result is favourable for my project, but i want to know what filter it is. The function also gave some result with operator parameter set to 1.
If someone knows what the operator values 0 and 1 does, please let me know.
推荐答案
在框架提供的枚举中使用直接代码永远不是一个好主意...
如果检查源代码(OpenCV已打开) GitHub!)你会看到这个:
It is never a good idea to use direct codes where enums provided by the framework...
If you check the source code (OpenCV is on GitHub!) you will see this:
switch( op )
{
case MORPH_ERODE:
// ...
break;
case MORPH_DILATE:
// ...
break;
case MORPH_OPEN:
break;
case CV_MOP_CLOSE:
// ...
break;
case CV_MOP_GRADIENT:
// ...
break;
case CV_MOP_TOPHAT:
// ...
break;
case CV_MOP_BLACKHAT:
// ...
break;
default:
CV_Error( CV_StsBadArg, "unknown morphological operation" );
}
如果你搜索后面的枚举,你会看到:
And if you search for the enum behind you will see this:
enum MorphTypes{
MORPH_ERODE = 0, //!< see cv::erode
MORPH_DILATE = 1, //!< see cv::dilate
MORPH_OPEN = 2, //!< an opening operation
//!< \f[\texttt{dst} = \mathrm{open} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \mathrm{erode} ( \texttt{src} , \texttt{element} ))\f]
MORPH_CLOSE = 3, //!< a closing operation
//!< \f[\texttt{dst} = \mathrm{close} ( \texttt{src} , \texttt{element} )= \mathrm{erode} ( \mathrm{dilate} ( \texttt{src} , \texttt{element} ))\f]
MORPH_GRADIENT = 4, //!< a morphological gradient
//!< \f[\texttt{dst} = \mathrm{morph\_grad} ( \texttt{src} , \texttt{element} )= \mathrm{dilate} ( \texttt{src} , \texttt{element} )- \mathrm{erode} ( \texttt{src} , \texttt{element} )\f]
MORPH_TOPHAT = 5, //!< "top hat"
//!< \f[\texttt{dst} = \mathrm{tophat} ( \texttt{src} , \texttt{element} )= \texttt{src} - \mathrm{open} ( \texttt{src} , \texttt{element} )\f]
MORPH_BLACKHAT = 6 //!< "black hat"
//!< \f[\texttt{dst} = \mathrm{blackhat} ( \texttt{src} , \texttt{element} )= \mathrm{close} ( \texttt{src} , \texttt{element} )- \texttt{src}\f]
};
这篇关于运算符0和1在OpenCV的MorphologyEx()函数中做了什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!