-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.cpp
87 lines (69 loc) · 1.92 KB
/
main.cpp
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/features2d.hpp>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>
#define DEBUG false
using namespace cv;
using namespace std;
void usage(int argc, char* argv[]){
cout << "Usage: " << argv[0] << " [image-list]" << endl;
cout << "Output: A list of images (one per line) that aren't blank" << endl;
}
bool is_whitepage(char* filename){
Mat im = imread(filename);
std::vector<KeyPoint> keypoints;
SimpleBlobDetector::Params params;
params.minThreshold = 10;
params.maxThreshold = 200;
params.filterByArea = true;
params.minArea = 20;
params.filterByCircularity = false;;
params.minCircularity = 1;
params.filterByConvexity = false;
params.minConvexity = 1;
params.filterByInertia = true;
params.minInertiaRatio = 0.01;
#if CV_MAJOR_VERSION < 3 // If you are using OpenCV 2
SimpleBlobDetector detector(params);
detector.detect( im, keypoints);
#else
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);
detector->detect( im, keypoints);
#endif
double blobs_ratio = (double) keypoints.size() / (1.0 * im.rows*im.cols);
if(DEBUG){
cout << "Blobs Ratio: " << blobs_ratio << endl;
cout << "We've detected " << keypoints.size() << " keypoints" << endl;
}
bool is_whitepage = false;
if (blobs_ratio < 1E-6) {
is_whitepage = true;
if(DEBUG)
cout << "This page is blank." << endl;
}
return is_whitepage;
}
int main(int argc, char* argv[]){
Mat image;
if(argc < 2){
cerr << "Invalid input" << endl;
usage(argc, argv);
return 1;
}
for (int i=1; i<argc; i++){
if(!is_whitepage(argv[i])){
cout << argv[i] << endl;
}
}
image = imread(argv[1]);
if(!image.data){
cerr << "No image data." << endl;
return 1;
}
}