-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimageDocument.cpp
183 lines (147 loc) · 4.47 KB
/
imageDocument.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* ArchiveVision: Compter Vision Engine for Digital Archives
*
* file: imageDocument.cpp
*
* Contains classes and functions for converting an image visual
* word histogram to an image document format and saving the image
* document to disk.
*
* Copyright (C) 2012 Carl Stahmer ([email protected])
* Early Modern Center, University of California, Santa Barbara
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Creative Commons licence, version 3.
*
* See http://creativecommons.org/licenses/by/3.0/legalcode for the
* complete licence.
*
* This program is distributed WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*/
#include "imageDocument.h"
using namespace cv;
using namespace std;
ImgDoc::ImgDoc()
{
}
ImgDoc::~ImgDoc()
{
}
/* need to modify this so that it first reads the scientific notation as
* a string and looks to see what the exponent is, then it should use
* this exponent to figure out the multiplier in int multiplier = pow(10, depth);
* Then, convert the scientific notation to an actual number. Then create to files,
* one for indexing, and one for querying. The indexing file should use the "frequency"
* kind of write out, where it repeats the word/number one time for every time it is
* in the histogram. The querying one shoudl construct a boolean query with AND
* separators. This might solve my problem with Lucene.
*/
string ImgDoc::makeVWString(vector<float> histogram, bool frequency, int depth, string handle, string &histogramsCSV) {
string retString;
int multiplier;
string dictWordID;
stringstream out;
int wholeNumberHist = 0;
vector<int> vectorExponents;
int medianExponentValue;
int exp;
float significand;
if (histogram.size() > 0) {
/*
cout << "Create Vector of Histograms" << endl;
for(int iq=0; iq<histogram.size(); iq++){
if (histogram[iq] != 0) {
significand = frexp(histogram[iq], &exp);
exp = exp * -1;
if (exp > 0) {
vectorExponents.push_back(exp);
}
}
}
cout << "End Creating Vecor of Histograms" << endl;
*/
/*
size_t n = vectorExponents.size() / 2;
nth_element(vectorExponents.begin(), vectorExponents.begin()+n, vectorExponents.end());
medianExponentValue = vectorExponents[n];
*/
//cout << handle << " ";
//histogramsCSV.append(handle);
//histogramsCSV.append(",");
for(int i=0; i<histogram.size(); i++){
out << i+1;
dictWordID = out.str();
if (histogram[i] > 0) {
for (float fi=0; fi<histogram[i]; fi++) {
//cout << "[" << i << ":" << fi << "]";
retString.append(dictWordID);
retString.append(" ");
}
}
/*
significand = frexp(histogram[i], &exp);
if (significand > 0) {
stringstream ssSig (stringstream::in | stringstream::out);
stringstream ssExp (stringstream::in | stringstream::out);
ssSig << significand;
ssExp << exp;
cout << significand << "e" << exp;
histogramsCSV.append(ssSig.str()); //// errors here. need to convert "significand" and "exp" to strings before I can assign them.
histogramsCSV.append("e");
histogramsCSV.append(ssExp.str());
} else {
cout << "0";
histogramsCSV.append("0");
}
if (i < (histogram.size() - 1)) {
cout << " ";
histogramsCSV.append(",");
}
exp = exp * -1;
// if (exp >= (medianExponentValue -1)) {
wholeNumberHist = (significand * pow(2, exp));
for (int ix=0; ix<wholeNumberHist; ix++) {
retString.append(dictWordID);
retString.append(" ");
}
// }
*/
/*
stringstream ss (stringstream::in | stringstream::out);
ss << histogram[i];
string test = ss.str();
cout << test << " ";
/*
/*
if (histogram[i] >= 0) {
wholeNumberHist = (int) ((histogram[i] * multiplier) + 0.5);
} else {
wholeNumberHist = (int) ((histogram[i] * multiplier) - 0.5);
}
if (wholeNumberHist > 0) {
if (frequency) {
for (int ix=0; ix<wholeNumberHist; ix++) {
retString.append(dictWordID);
retString.append(" ");
}
} else {
retString.append(dictWordID);
retString.append(" ");
}
}
*/
//clears the outstr before the next read in of ID
out.str("");
}
//cout << endl;
//histogramsCSV.append("\r\n");
}
return retString;
}
void ImgDoc::test() {
cout<<"I'm here"<<endl;
}