Commit 8123bb944c91f685929a2cece52154ffae8e1e4a
1 parent
8c83f309
Exists in
master
and in
2 other branches
Definicao da taxa de confiabilidade na chamada do CORE implementada.
Showing
6 changed files
with
99 additions
and
42 deletions
Show diff stats
.gitignore
main.cpp
| @@ -25,7 +25,9 @@ using namespace std; | @@ -25,7 +25,9 @@ using namespace std; | ||
| 25 | void serviceCC(); | 25 | void serviceCC(); |
| 26 | void serviceSRT(char* path_in, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* username); | 26 | void serviceSRT(char* path_in, char* path_srt, char* sublanguage, char* position, char* size, char* transparency, char* username); |
| 27 | void serviceOnlySRT(char* path_file, char* transparency, char* username); | 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 | void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username); | 29 | void serviceREC(char* path_video, char* sublanguage, char* position, char* size, char* transparency, char* username); |
| 30 | + | ||
| 29 | void serviceText(char* path_text, char* transparency, char* username, char* client_type); | 31 | void serviceText(char* path_text, char* transparency, char* username, char* client_type); |
| 30 | void serviceREC2(); | 32 | void serviceREC2(); |
| 31 | void help(); | 33 | void help(); |
| @@ -41,7 +43,7 @@ bool isFailed; | @@ -41,7 +43,7 @@ bool isFailed; | ||
| 41 | 43 | ||
| 42 | int main(int argc, char* argv[]) { | 44 | int main(int argc, char* argv[]) { |
| 43 | 45 | ||
| 44 | - | 46 | + cout << argc << endl; |
| 45 | struct timeval tv1, tv2; | 47 | struct timeval tv1, tv2; |
| 46 | double t1, t2; | 48 | double t1, t2; |
| 47 | 49 | ||
| @@ -71,8 +73,12 @@ int main(int argc, char* argv[]) { | @@ -71,8 +73,12 @@ int main(int argc, char* argv[]) { | ||
| 71 | help(); | 73 | help(); |
| 72 | return 1; | 74 | return 1; |
| 73 | } | 75 | } |
| 76 | + if (argc == 8) | ||
| 74 | serviceREC(argv[2], argv[3], argv[4], argv[5], | 77 | serviceREC(argv[2], argv[3], argv[4], argv[5], |
| 75 | argv[6], argv[7]); | 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 | break; | 82 | break; |
| 77 | case 4: | 83 | case 4: |
| 78 | if(argc <= 5){ | 84 | if(argc <= 5){ |
| @@ -137,6 +143,34 @@ void serviceCC(){ | @@ -137,6 +143,34 @@ void serviceCC(){ | ||
| 137 | } | 143 | } |
| 138 | 144 | ||
| 139 | void serviceREC(char* path_video, char* sublanguage, | 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 | char* position, char* size, char* transparency, char* id){ | 174 | char* position, char* size, char* transparency, char* id){ |
| 141 | 175 | ||
| 142 | filename = createFileToResponse(id); | 176 | filename = createFileToResponse(id); |
recognize/src/include/recognize.h
| @@ -15,8 +15,9 @@ using namespace std; | @@ -15,8 +15,9 @@ using namespace std; | ||
| 15 | class Recognize { | 15 | class Recognize { |
| 16 | 16 | ||
| 17 | public: | 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 | Recognize(char* _pathVideo, int _inputType, char* id); | 21 | Recognize(char* _pathVideo, int _inputType, char* id); |
| 21 | ~Recognize(); | 22 | ~Recognize(); |
| 22 | 23 | ||
| @@ -43,10 +44,9 @@ private: | @@ -43,10 +44,9 @@ private: | ||
| 43 | 44 | ||
| 44 | char* pathVideo; | 45 | char* pathVideo; |
| 45 | string id; | 46 | string id; |
| 47 | + float confidenceRate; | ||
| 46 | bool finished; | 48 | bool finished; |
| 47 | - | ||
| 48 | - float sizeScores; | ||
| 49 | - float avgScores; | 49 | + vector<float> scores; |
| 50 | 50 | ||
| 51 | /** inputType: 1 = RawFile, 2 = Mic */ | 51 | /** inputType: 1 = RawFile, 2 = Mic */ |
| 52 | int inputType, frequency, sizeBlocs; | 52 | int inputType, frequency, sizeBlocs; |
| @@ -60,10 +60,11 @@ private: | @@ -60,10 +60,11 @@ private: | ||
| 60 | void breakVideoParts(int timeTotal); | 60 | void breakVideoParts(int timeTotal); |
| 61 | 61 | ||
| 62 | void executeJuliusEngine(); | 62 | void executeJuliusEngine(); |
| 63 | - std::list<char*>* filterOutputJulius(); | ||
| 64 | - void confidenceJulius(); | 63 | + void filterOutputJulius(); |
| 64 | + void generateConfidence(); | ||
| 65 | void notifyListeners(char* text); | 65 | void notifyListeners(char* text); |
| 66 | void cleanFiles(); | 66 | void cleanFiles(); |
| 67 | void createDir(); | 67 | void createDir(); |
| 68 | + bool getConfidence(int i); | ||
| 68 | 69 | ||
| 69 | }; | 70 | }; |
recognize/src/recognize.cpp
| @@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
| 18 | #define INPUT_PATTERN 1 /* 1 = Raw file, 2 = Mic */ | 18 | #define INPUT_PATTERN 1 /* 1 = Raw file, 2 = Mic */ |
| 19 | #define BLOCS_PATTERN 10 | 19 | #define BLOCS_PATTERN 10 |
| 20 | #define SIZE_BUFFER 256 | 20 | #define SIZE_BUFFER 256 |
| 21 | -#define CONFIDENCE_RATE 0.80 | 21 | +#define CONFIDENCE_RATE 0.40 |
| 22 | 22 | ||
| 23 | #define PATH_GTAAAS_WEB "gtaaas_user/gtaaas_web/public/uploads/videos/" | 23 | #define PATH_GTAAAS_WEB "gtaaas_user/gtaaas_web/public/uploads/videos/" |
| 24 | #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav" | 24 | #define PATH_AUDIO_ORIGIN "/audio/origin/audio_origin.wav" |
| @@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
| 29 | #define FILENAME_CONFIDENCEOUT "/audio/confidence" | 29 | #define FILENAME_CONFIDENCEOUT "/audio/confidence" |
| 30 | 30 | ||
| 31 | #define FIND_CONFIDENCE "\"cmscore1:\"" | 31 | #define FIND_CONFIDENCE "\"cmscore1:\"" |
| 32 | -#define FIND_SENTENCE "\"pass1_best:\"" | 32 | +#define FIND_SENTENCE "\"sentence1:\"" |
| 33 | 33 | ||
| 34 | #define FILENAME_AUDIOPART "audio00" | 34 | #define FILENAME_AUDIOPART "audio00" |
| 35 | 35 | ||
| @@ -49,7 +49,23 @@ Recognize::Recognize(char* _pathVideo, char* _id) { | @@ -49,7 +49,23 @@ Recognize::Recognize(char* _pathVideo, char* _id) { | ||
| 49 | stringstream ss; | 49 | stringstream ss; |
| 50 | ss << _id; | 50 | ss << _id; |
| 51 | ss >> id; | 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 | DPRINTF("Done!\n"); | 69 | DPRINTF("Done!\n"); |
| 54 | } | 70 | } |
| 55 | 71 | ||
| @@ -87,24 +103,15 @@ void Recognize::initialize() { | @@ -87,24 +103,15 @@ void Recognize::initialize() { | ||
| 87 | finished = false; | 103 | finished = false; |
| 88 | 104 | ||
| 89 | createDir(); | 105 | createDir(); |
| 90 | - | ||
| 91 | extractAudioFromVideo(); | 106 | extractAudioFromVideo(); |
| 92 | - | ||
| 93 | breakVideoParts(getTimeMediaSec()); | 107 | breakVideoParts(getTimeMediaSec()); |
| 94 | - | ||
| 95 | executeJuliusEngine(); | 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 | finished = true; | 113 | finished = true; |
| 107 | - cleanFiles(); | 114 | + |
| 108 | } | 115 | } |
| 109 | 116 | ||
| 110 | 117 | ||
| @@ -253,7 +260,7 @@ void Recognize::executeJuliusEngine() { | @@ -253,7 +260,7 @@ void Recognize::executeJuliusEngine() { | ||
| 253 | 260 | ||
| 254 | } | 261 | } |
| 255 | 262 | ||
| 256 | -void Recognize::confidenceJulius() { | 263 | +void Recognize::generateConfidence() { |
| 257 | 264 | ||
| 258 | string command = "cat "; | 265 | string command = "cat "; |
| 259 | command.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep "). | 266 | command.append(PATH_GTAAAS_WEB).append(id).append(FILENAME_RECOGNIZED_OUT).append(" | grep "). |
| @@ -271,36 +278,35 @@ void Recognize::confidenceJulius() { | @@ -271,36 +278,35 @@ void Recognize::confidenceJulius() { | ||
| 271 | } else { | 278 | } else { |
| 272 | string line; | 279 | string line; |
| 273 | float tmp; | 280 | float tmp; |
| 274 | - avgScores = 0; | ||
| 275 | do { | 281 | do { |
| 276 | getline(in, line); | 282 | getline(in, line); |
| 277 | std::istringstream buf(line); | 283 | std::istringstream buf(line); |
| 278 | if (line.length() > 0) { | 284 | if (line.length() > 0) { |
| 279 | istream_iterator<std::string> beg(buf), end; | 285 | istream_iterator<std::string> beg(buf), end; |
| 280 | vector<string> tokens(beg, end); | 286 | vector<string> tokens(beg, end); |
| 287 | + float sizeScores = 0; | ||
| 288 | + float avgScores = 0; | ||
| 281 | int i; | 289 | int i; |
| 282 | for(i=2; i < tokens.size()-1; i++){ | 290 | for(i=2; i < tokens.size()-1; i++){ |
| 283 | istringstream(tokens[i]) >> tmp; | 291 | istringstream(tokens[i]) >> tmp; |
| 284 | avgScores += tmp; | 292 | avgScores += tmp; |
| 285 | sizeScores++; | 293 | sizeScores++; |
| 286 | } | 294 | } |
| 295 | + scores.push_back(avgScores/sizeScores); | ||
| 287 | } | 296 | } |
| 288 | } while (!in.eof()); | 297 | } while (!in.eof()); |
| 289 | in.close(); | 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 | std::list<char*> *sentences; | 311 | std::list<char*> *sentences; |
| 306 | sentences = new std::list<char*>(); | 312 | sentences = new std::list<char*>(); |
| @@ -315,7 +321,7 @@ std::list<char*>* Recognize::filterOutputJulius() { | @@ -315,7 +321,7 @@ std::list<char*>* Recognize::filterOutputJulius() { | ||
| 315 | int count_lines = 0; | 321 | int count_lines = 0; |
| 316 | 322 | ||
| 317 | string path; | 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 | ifstream in(path.c_str()); | 325 | ifstream in(path.c_str()); |
| 320 | string strFilter; | 326 | string strFilter; |
| 321 | 327 | ||
| @@ -332,8 +338,12 @@ std::list<char*>* Recognize::filterOutputJulius() { | @@ -332,8 +338,12 @@ std::list<char*>* Recognize::filterOutputJulius() { | ||
| 332 | strFilter = line.substr(strlen(FIND_SENTENCE), sizeLine); | 338 | strFilter = line.substr(strlen(FIND_SENTENCE), sizeLine); |
| 333 | sentence_ptr = new char[strFilter.length()+1]; | 339 | sentence_ptr = new char[strFilter.length()+1]; |
| 334 | strcpy(sentence_ptr, (char*) strFilter.c_str()); | 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 | } while (!in.eof()); | 347 | } while (!in.eof()); |
| 338 | in.close(); | 348 | in.close(); |
| 339 | } | 349 | } |
| @@ -341,9 +351,6 @@ std::list<char*>* Recognize::filterOutputJulius() { | @@ -341,9 +351,6 @@ std::list<char*>* Recognize::filterOutputJulius() { | ||
| 341 | /*char* ptr_strFilter; | 351 | /*char* ptr_strFilter; |
| 342 | ptr_strFilter = (char*) malloc (strFilter.length()+1); | 352 | ptr_strFilter = (char*) malloc (strFilter.length()+1); |
| 343 | strcpy(ptr_strFilter, (char*) strFilter.c_str());*/ | 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,6 +17,8 @@ private: | ||
| 17 | 17 | ||
| 18 | public: | 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 | ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType); | 22 | ServiceWindowGenerationFromREC(char* path_video, int sublanguage, int position, int size, int transparency, char* id, int _serviceType); |
| 21 | 23 | ||
| 22 | ~ServiceWindowGenerationFromREC(); | 24 | ~ServiceWindowGenerationFromREC(); |
servico/src/serviceWindowGenerationFromREC.cpp
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | using namespace std; | 3 | using namespace std; |
| 4 | 4 | ||
| 5 | ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | 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 | path_input = path_video; | 8 | path_input = path_video; |
| 9 | setSubLanguage(sublanguage); | 9 | setSubLanguage(sublanguage); |
| @@ -11,10 +11,22 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | @@ -11,10 +11,22 @@ ServiceWindowGenerationFromREC::ServiceWindowGenerationFromREC( | ||
| 11 | setSize(size); | 11 | setSize(size); |
| 12 | setTransparency(transparency); | 12 | setTransparency(transparency); |
| 13 | setServiceType(_serviceType); | 13 | setServiceType(_serviceType); |
| 14 | - rec = new Recognize(path_input, id); | 14 | + rec = new Recognize(path_input, id, rate); |
| 15 | DPRINTF("Done!\n"); | 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 | ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { | 31 | ServiceWindowGenerationFromREC::~ServiceWindowGenerationFromREC() { |
| 20 | delete rec; | 32 | delete rec; |