/* * Ecrit un code dans un fichier * @param file : Le fichier dans lequel lire * @param code_size : La taille du code à lire * @param nb_prev : Le décalage par rapport au code précédent lu, et celui pour le suivant en sortie * @param for_next : Le code qui sera utile pour la prochaine lecture * @param from_prev : Le code lu lors de la lecture précédente * @return : Le code lu * Exemple d'utilisation : * int cr = 0, nb_prev = 0, n; * int i = 0; * FILE* file = fopen("a.out", "rb"); * * do * { * cr = read_c(file, 9, &nb_prev, &n, n); * i++; * } while(cr != 256); // Correspond à EOF */ int read_c(FILE* file, int code_size, int* nb_prev, int* for_next, int from_prev) { int i; int res = from_prev; int nb_read = (code_size / RW_SIZE) + 1; int fn = RW_SIZE - (code_size - *nb_prev) % RW_SIZE; int mask; unsigned char r; if(fn == RW_SIZE) fn = 0; if(*nb_prev == 0) i = 0; else i = 1; while(i < nb_read) { r = read_b(file); res <<= RW_SIZE; res += r; i++; } mask = (1 << fn) - 1; *for_next = res & mask; res >>= fn; *nb_prev = fn; return res; }
// This function takes tif/box pair of files and runs recognition on the image, // while making sure that the word bounds that tesseract identified roughly // match to those specified by the input box file. For each word (ngram in a // single bounding box from the input box file) it outputs the ocred result, // the correct label, rating and certainty. void Tesseract::recog_training_segmented(const STRING &fname, PAGE_RES *page_res, volatile ETEXT_DESC *monitor, FILE *output_file) { STRING box_fname = fname; const char *lastdot = strrchr(box_fname.string(), '.'); if (lastdot != NULL) box_fname[lastdot - box_fname.string()] = '\0'; box_fname += ".box"; // read_next_box() will close box_file FILE *box_file = open_file(box_fname.string(), "r"); PAGE_RES_IT page_res_it; page_res_it.page_res = page_res; page_res_it.restart_page(); char label[kBoxReadBufSize]; // Process all the words on this page. TBOX tbox; // tesseract-identified box TBOX bbox; // box from the box file bool keep_going; int line_number = 0; do { keep_going = read_t(&page_res_it, &tbox); keep_going &= read_b(applybox_page, &line_number, box_file, label, &bbox); // Align bottom left points of the TBOXes. while (keep_going && !NearlyEqual<int>(tbox.bottom(), bbox.bottom(), kMaxBoxEdgeDiff)) { keep_going = (bbox.bottom() < tbox.bottom()) ? read_t(&page_res_it, &tbox) : read_b(applybox_page, &line_number, box_file, label, &bbox); } while (keep_going && !NearlyEqual<int>(tbox.left(), bbox.left(), kMaxBoxEdgeDiff)) { keep_going = (bbox.left() > tbox.left()) ? read_t(&page_res_it, &tbox) : read_b(applybox_page, &line_number, box_file, label, &bbox); } // OCR the word if top right points of the TBOXes are similar. if (keep_going && NearlyEqual<int>(tbox.right(), bbox.right(), kMaxBoxEdgeDiff) && NearlyEqual<int>(tbox.top(), bbox.top(), kMaxBoxEdgeDiff)) { ambigs_classify_and_output(page_res_it.prev_word(), page_res_it.prev_row(), page_res_it.prev_block(), label, output_file); } } while (keep_going); }
void read_config(HMM* word, char **files,int job, int states, int len) { // variables int i; int N = states; int T = len; word->nstates = N; word->len = T; // allocate parameters word->b = (float*)malloc(sizeof(float)*N*T); word->a = (float*)malloc(sizeof(float)*N*N); word->pri = (float*)malloc(sizeof(float)*N); for(i = 0; i < 3; ++i){ //printf("%s\n",files[job*3+i]); // read B if(i == 0){ //printf("read B[%d][%d] \t\t", N, T); read_b(files[job*3],word,N,T); //printf("done!\n"); } // read A if(i == 1){ //printf("read A[%d][%d] \t\t", N, N); read_a(files[job*3+1],word,N,N); //printf("done!\n"); } // read prior if(i == 2){ //printf("read prior[%d] \t\t", N); read_pri(files[job*3+2],word,N); //printf("done!\n"); } } }
PACKET* packet_read(int socket) { PACKET *p = malloc(sizeof(PACKET)); p->command = read_i(socket); p->args_count = read_i(socket); PACKET_ARG **args = malloc(p->args_count * sizeof(PACKET_ARG*)); for (uint32_t i = 0; i < p->args_count; i ++) { PACKET_ARG *arg = malloc(sizeof(PACKET_ARG)); arg->length = read_i(socket); arg->arg = read_b(socket, arg->length); args[i] = arg; } p->args = args; packet_dump(p); return p; }
bool Color::read(yarp::os::idl::WireReader& reader) { if (!read_r(reader)) return false; if (!read_g(reader)) return false; if (!read_b(reader)) return false; return !reader.isError(); }