-
Notifications
You must be signed in to change notification settings - Fork 4
/
feature_gen.cpp
62 lines (57 loc) · 1.36 KB
/
feature_gen.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
#include<bits/stdc++.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include<ctime>
#include <fstream>
#include <sstream>
using namespace cv;
using namespace std;
Mat img;
int main()
{
int number = 100000;
ofstream myfile;
myfile.open ("data/features.txt");
int num,x,y;
string s,s1,s2,s3;
while(number>=1)
{
stringstream ss;
// if (100000-number==46242)
// {
// myfile << x/num << " " << y/num << " " <<num << endl;
// continue;
// }
ss<<(100000-number);
s = "dataset/";
s1 = "img";
s2 = ss.str();
s3 = ".jpg";
num = 0;
x = 0;
y = 0;
img = imread(s+s1+s2+s3,0);
//cout << img.rows << endl;
for (int i = 0 ; i < img.rows ; i++)
{
for (int j = 0 ; j < img.cols ; j++)
{
//cout << (int)img.at<uchar>(i,j) << " ";
if ((int)img.at<uchar>(i,j)>150)
{
//cout << i << " " << j << " " << (int)img.at<uchar>(i,j) << endl;
num++;
x+=i;
y+=j;
}
}
}
number--;
//cout << 100000-number << " " << num << endl;
if (num==0)
myfile << 0 << " " << 0 << " " << 1 << endl;
else
myfile << x/num << " " << y/num << " " <<num << endl;
}
}