【问题标题】:How to detect Blur rate of a face effectively in c++?如何在 C++ 中有效地检测人脸的模糊率?
【发布时间】:2020-06-20 13:38:11
【问题描述】:

我正在尝试使用以下代码检测人脸图像的模糊率。

cv::Mat greyMat;
cv::Mat laplacianImage;
cv::Mat imageClone = LapMat.clone();

cv::resize(imageClone, imageClone, cv::Size(150, 150), 0, 0, cv::INTER_CUBIC);

cv::cvtColor(imageClone, greyMat, CV_BGR2GRAY);
Laplacian(greyMat, laplacianImage, CV_64F);

cv::Scalar mean, stddev; // 0:1st channel, 1:2nd channel and 2:3rd channel
meanStdDev(laplacianImage, mean, stddev, cv::Mat());
double variance = stddev.val[0] * stddev.val[0];

cv::Mat M = (cv::Mat_(3, 1)

cv::Mat Lx;
cv::sepFilter2D(LapMat, Lx, CV_64F, M, G);

cv::Mat Ly;
cv::sepFilter2D(LapMat, Ly, CV_64F, G, M);

cv::Mat FM = cv::abs(Lx) + cv::abs(Ly);

double focusMeasure = cv::mean(FM).val[0];
return focusMeasure;

它有时会给出不好的结果,如附图所示。

是否有检测模糊面孔的最佳实践方法? 我附上了一个示例图像,上面的代码得分很高,这是错误的。

最好的

【问题讨论】:

  • 您想检测模糊率或模糊人脸吗?你的问题我不清楚

标签: c++ opencv blurry


【解决方案1】:

我不确定你如何解释你的结果。为了测量模糊,您通常获取 Blur Detector 的输出(一个数字)并将其与阈值进行比较,然后确定输入是否实际上是模糊的。我在您的代码中没有看到这样的比较。

有几种方法可以测量“模糊度”,或者更确切地说,是锐度。让我们来看一个。它涉及计算拉普拉斯算子的方差,然后将其与预期值进行比较。这是代码:

//read the image and convert it to grayscale:
cv::Mat inputImage = cv::imread( "dog.png" );
cv::Mat gray;
cv::cvtColor( inputImage, gray, cv::COLOR_RGB2GRAY );

//Cool, let's compute the laplacian of the gray image:
cv::Mat laplacianImage;
cv::Laplacian( gray, laplacianImage, CV_64F );

//Prepare to compute the mean and standard deviation of the laplacian:
cv::Scalar mean, stddev; 
cv::meanStdDev( laplacianImage, mean, stddev, cv::Mat() );

//Let’s compute the variance:
double variance = stddev.val[0] * stddev.val[0];

到目前为止,我们已经有效地计算了拉普拉斯算子的方差,但我们仍然需要与阈值进行比较:

double blurThreshold = 300;

if ( variance <= blurThreshold ) {
    std::cout<<"Input image is blurry!"<<std::endl;
} else {
    std::cout<<"Input image is sharp"<<std::endl;
}

让我们看看结果。 Theseare我的测试图像。我已经在图像的左下角打印了方差值。阈值为300,蓝色文字在限制范围内,红色文字在限制范围内。

【讨论】:

  • 嗨,是的,有门槛。你检查我的图像值了吗?
  • 没有。你用我提出的检测方法检查你的图像怎么样?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-12-01
  • 2016-11-18
  • 2012-02-25
  • 2014-01-31
  • 2010-12-31
  • 1970-01-01
  • 2020-07-07
相关资源
最近更新 更多