-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblurDetection.cpp
More file actions
40 lines (28 loc) · 885 Bytes
/
blurDetection.cpp
File metadata and controls
40 lines (28 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <opencv2/opencv.hpp>
#include "opencv2/xphoto.hpp"
int main( int argc, char *argv[] ){
if( argc != 2) {
std::cout << "Proper usage is" << argv[0] << " <filename>\r\n";
return -1;
}
cv::Mat image, grayscale, laplaced;
image = cv::imread( argv[1] );
//Convert to Grayscale
cvtColor( image, grayscale, CV_BGR2GRAY );
//Calculate the Laplacian for this
cv::Laplacian( grayscale, laplaced, CV_16S );
//Variables for calculating the variance
double sqMean, meanSq, variance;
sqMean = meanSq = variance = 0.0;
//Calculate one of the terms
meanSq = cv::mean( laplaced )[0];
meanSq = meanSq * meanSq;
//Calculate Second term
cv::pow( laplaced, 2., laplaced );
sqMean = cv::mean( laplaced )[0];
//Finish the variance calculation
variance = sqMean - meanSq;
std::cout << "Blur value is: " << variance << "\r\n";
return 0;
}