Commit 8123bb944c91f685929a2cece52154ffae8e1e4a

Authored by Erickson Silva
1 parent 8c83f309
Exists in master and in 2 other branches api, devel

Definicao da taxa de confiabilidade na chamada do CORE implementada.

.gitignore
1 1 #general
2 2  
3 3 *.ts
  4 +*.flv
4 5 *.swp*
5 6 *.class
6 7 *.a
... ...
main.cpp
... ... @@ -25,7 +25,9 @@ using namespace std;
25 25 void serviceCC();
26 26 void serviceSRT(char* path_in, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* username);
27 27 void serviceOnlySRT(char* path_file, char* transparency, char* username);
  28 +void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username, char* rate);
28 29 void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username);
  30 +
29 31 void serviceText(char* path_text, char* transparency, char* username, char* client_type);
30 32 void serviceREC2();
31 33 void help();
... ... @@ -41,7 +43,7 @@ bool isFailed;
41 43  
42 44 int main(int argc, char* argv[]) {
43 45  
44   -
  46 + cout << argc << endl;
45 47 struct timeval tv1, tv2;
46 48 double t1, t2;
47 49  
... ... @@ -71,8 +73,12 @@ int main(int argc, char* argv[]) {
71 73 help();
72 74 return 1;
73 75 }
  76 + if (argc == 8)
74 77 serviceREC(argv[2], argv[3], argv[4], argv[5],
75 78 argv[6], argv[7]);
  79 + else
  80 + serviceREC(argv[2], argv[3], argv[4], argv[5],
  81 + argv[6], argv[7], argv[8]);
76 82 break;
77 83 case 4:
78 84 if(argc <= 5){
... ... @@ -137,6 +143,34 @@ void serviceCC(){
137 143 }
138 144  
139 145 void serviceREC(char* path_video, char* sublanguage,
  146 + char* position, char* size, char* transparency, char* id, char* rate){
  147 +
  148 + filename = createFileToResponse(id);
  149 +
  150 + ServiceWindowGenerationFromREC * service_rec;
  151 + service_rec = new ServiceWindowGenerationFromREC(
  152 + path_video,
  153 + (int) atoi(sublanguage),
  154 + (int) atoi(position),
  155 + (int) atoi(size),
  156 + (int) atoi(transparency),
  157 + id, 3, rate);
  158 +
  159 + try{
  160 + service_rec->initialize();
  161 + }catch(ServiceException ex){
  162 + fail(ex.getMessage());
  163 + hasFailed();
  164 + return;
  165 + }
  166 + while(service_rec->isRunning()){
  167 + sleep(2);
  168 + }
  169 + updateRequestStatus(filename.c_str(), id, "true");
  170 + delete service_rec;
  171 +}
  172 +
  173 +void serviceREC(char* path_video, char* sublanguage,
140 174 char* position, char* size, char* transparency, char* id){
141 175  
142 176 filename = createFileToResponse(id);
... ...
recognize/src/include/recognize.h
... ... @@ -15,8 +15,9 @@ using namespace std;
15 15 class Recognize {
16 16  
17 17 public:
18   -
19   - Recognize(char* _pathVideo, char* id);
  18 +
  19 + Recognize(char* _pathVideo, char* id);
  20 + Recognize(char* _pathVideo, char* id, char* rate);
20 21 Recognize(char* _pathVideo, int _inputType, char* id);
21 22 ~Recognize();
22 23  
... ... @@ -43,10 +44,9 @@ private:
43 44  
44 45 char* pathVideo;
45 46 string id;
  47 + float confidenceRate;
46 48 bool finished;
47   -
48   - float sizeScores;
49   - float avgScores;
  49 + vector<float> scores;
50 50  
51 51 /** inputType: 1 = RawFile, 2 = Mic */
52 52 int inputType, frequency, sizeBlocs;
... ... @@ -60,10 +60,11 @@ private:
60 60 void breakVideoParts(int timeTotal);
61 61  
62 62 void executeJuliusEngine();
63   - std::list<char*>* filterOutputJulius();
64   - void confidenceJulius();
  63 + void filterOutputJulius();
  64 + void generateConfidence();
65 65 void notifyListeners(char* text);
66 66 void cleanFiles();
67 67 void createDir();
  68 + bool getConfidence(int i);
68 69  
69 70 };
... ...
recognize/src/recognize.cpp
... ... @@ -18,7 +18,7 @@
18 18 #define INPUT_PATTERN 1 /* 1 = Raw file, 2 = Mic */
19 19 #define BLOCS_PATTERN 10
20 20 #define SIZE_BUFFER 256
21   -#define CONFIDENCE_RATE 0.80
  21 +#define CONFIDENCE_RATE 0.40
22 22  
23 23 #define PATH_GTAAAS_WEB "gtaaas_user/gtaaas_web/public/uploads/videos/"
24 24 #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav"
... ... @@ -29,7 +29,7 @@
29 29 #define FILENAME_CONFIDENCEOUT "/audio/confidence"
30 30  
31 31 #define FIND_CONFIDENCE "\"cmscore1:\""
32   -#define FIND_SENTENCE "\"pass1_best:\""
  32 +#define FIND_SENTENCE "\"sentence1:\""
33 33  
34 34 #define FILENAME_AUDIOPART "audio00"
35 35  
... ... @@ -49,7 +49,23 @@ Recognize::Recognize(char* _pathVideo, char* _id) {
49 49 stringstream ss;
50 50 ss << _id;
51 51 ss >> id;
52   - printf("ID: %s\n", id.c_str());
  52 + confidenceRate=CONFIDENCE_RATE;
  53 + DPRINTF("Done!\n");
  54 +}
  55 +
  56 +Recognize::Recognize(char* _pathVideo, char* _id, char* rate) {
  57 +
  58 + listeners = new list<RecognizeListener*>();
  59 + pathVideo = _pathVideo;
  60 + inputType = INPUT_PATTERN;
  61 + frequency = FREQUENCY_PATTERN;
  62 + sizeBlocs = BLOCS_PATTERN;
  63 + stringstream ss;
  64 + ss << _id;
  65 + ss >> id;
  66 + istringstream(rate) >> confidenceRate;
  67 + if (confidenceRate == 0)
  68 + confidenceRate=CONFIDENCE_RATE;
53 69 DPRINTF("Done!\n");
54 70 }
55 71  
... ... @@ -87,24 +103,15 @@ void Recognize::initialize() {
87 103 finished = false;
88 104  
89 105 createDir();
90   -
91 106 extractAudioFromVideo();
92   -
93 107 breakVideoParts(getTimeMediaSec());
94   -
95 108 executeJuliusEngine();
  109 + generateConfidence();
  110 + filterOutputJulius();
  111 + cleanFiles();
96 112  
97   - confidenceJulius();
98   -
99   - std::list<char*> *list_sentences;
100   - list_sentences = filterOutputJulius();
101   -
102   - std::list<char*>::iterator it;
103   - for (it = list_sentences->begin(); it != list_sentences->end(); it++)
104   - notifyListeners((*it));
105   -
106 113 finished = true;
107   - cleanFiles();
  114 +
108 115 }
109 116  
110 117  
... ... @@ -253,7 +260,7 @@ void Recognize::executeJuliusEngine() {
253 260  
254 261 }
255 262  
256   -void Recognize::confidenceJulius() {
  263 +void Recognize::generateConfidence() {
257 264  
258 265 string command = "cat ";
259 266 command.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep ").
... ... @@ -271,36 +278,35 @@ void Recognize::confidenceJulius() {
271 278 } else {
272 279 string line;
273 280 float tmp;
274   - avgScores = 0;
275 281 do {
276 282 getline(in, line);
277 283 std::istringstream buf(line);
278 284 if (line.length() > 0) {
279 285 istream_iterator<std::string> beg(buf), end;
280 286 vector<string> tokens(beg, end);
  287 + float sizeScores = 0;
  288 + float avgScores = 0;
281 289 int i;
282 290 for(i=2; i < tokens.size()-1; i++){
283 291 istringstream(tokens[i]) >> tmp;
284 292 avgScores += tmp;
285 293 sizeScores++;
286 294 }
  295 + scores.push_back(avgScores/sizeScores);
287 296 }
288 297 } while (!in.eof());
289 298 in.close();
290   - avgScores /= sizeScores;
291 299 }
  300 +}
292 301  
293   - cout << "Média: " << avgScores << endl;
294   -
295   - if (avgScores < CONFIDENCE_RATE){
296   - finished = true;
297   - cleanFiles();
298   - throw RecognizeException("O vídeo selecionado tem baixa qualidade. Tente novamente com outro vídeo.");
299   - }
  302 +bool Recognize::getConfidence(int i){
  303 + if (scores[i] < confidenceRate)
  304 + return false;
  305 + return true;
300 306 }
301 307  
302 308  
303   -std::list<char*>* Recognize::filterOutputJulius() {
  309 +void Recognize::filterOutputJulius() {
304 310  
305 311 std::list<char*> *sentences;
306 312 sentences = new std::list<char*>();
... ... @@ -315,7 +321,7 @@ std::list&lt;char*&gt;* Recognize::filterOutputJulius() {
315 321 int count_lines = 0;
316 322  
317 323 string path;
318   - path.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_CONFIDENCEOUT);
  324 + path.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_FILTEROUT);
319 325 ifstream in(path.c_str());
320 326 string strFilter;
321 327  
... ... @@ -332,8 +338,12 @@ std::list&lt;char*&gt;* Recognize::filterOutputJulius() {
332 338 strFilter = line.substr(strlen(FIND_SENTENCE), sizeLine);
333 339 sentence_ptr = new char[strFilter.length()+1];
334 340 strcpy(sentence_ptr, (char*) strFilter.c_str());
335   - sentences->push_back(sentence_ptr);
  341 + if(getConfidence(count_lines))
  342 + notifyListeners(sentence_ptr);
  343 + else
  344 + notifyListeners((char*) "SENTENCA_COM_BAIXA_QUALIDADE");
336 345 }
  346 + count_lines++;
337 347 } while (!in.eof());
338 348 in.close();
339 349 }
... ... @@ -341,9 +351,6 @@ std::list&lt;char*&gt;* Recognize::filterOutputJulius() {
341 351 /*char* ptr_strFilter;
342 352 ptr_strFilter = (char*) malloc (strFilter.length()+1);
343 353 strcpy(ptr_strFilter, (char*) strFilter.c_str());*/
344   -
345   - return sentences;
346   -
347 354 }
348 355  
349 356  
... ...
servico/src/include/serviceWindowGenerationFromREC.h
... ... @@ -17,6 +17,8 @@ private:
17 17  
18 18 public:
19 19  
  20 + ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType, char* rate);
  21 +
20 22 ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType);
21 23  
22 24 ~ServiceWindowGenerationFromREC();
... ...
servico/src/serviceWindowGenerationFromREC.cpp
... ... @@ -3,7 +3,7 @@
3 3 using namespace std;
4 4  
5 5 ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
6   - char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType) {
  6 + char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType, char* rate) {
7 7  
8 8 path_input = path_video;
9 9 setSubLanguage(sublanguage);
... ... @@ -11,10 +11,22 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
11 11 setSize(size);
12 12 setTransparency(transparency);
13 13 setServiceType(_serviceType);
14   - rec = new Recognize(path_input, id);
  14 + rec = new Recognize(path_input, id, rate);
15 15 DPRINTF("Done!\n");
16 16 }
17 17  
  18 +ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC(
  19 + char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType) {
  20 +
  21 + path_input = path_video;
  22 + setSubLanguage(sublanguage);
  23 + setPosition(position);
  24 + setSize(size);
  25 + setTransparency(transparency);
  26 + setServiceType(_serviceType);
  27 + rec = new Recognize(path_input, id);
  28 + DPRINTF("Done!\n");
  29 +}
18 30  
19 31 ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() {
20 32 delete rec;
... ...