public void Init(params string[] books) { bool retrain = PGetb("retrain"); bool randomize = PGetb("randomize"); string cbookstore = PGet("cbookstore"); bookstores.Clear(); all_lines.Clear(); cseg_variant = "cseg.gt"; text_variant = "gt"; if (retrain) { cseg_variant = "cseg"; text_variant = ""; } int nbooks = books.Length; bookstores.Resize(nbooks); int totalNumberOfPages = 0; for (int i = 0; i < nbooks; i++) { bookstores[i] = ComponentCreator.MakeComponent <IBookStore>(cbookstore); bookstores[i].SetPrefix(books[i].Trim()); Global.Debugf("info", "{0}: {1} pages", books[i], bookstores[i].NumberOfPages()); totalNumberOfPages += bookstores[i].NumberOfPages(); } //CHECK_ARG(totalNumberOfPages > 0, "totalNumberOfPages > 0"); // compute a list of all lines Intarray triple = new Intarray(3); for (int i = 0; i < nbooks; i++) { for (int j = 0; j < bookstores[i].NumberOfPages(); j++) { for (int k = 0; k < bookstores[i].LinesOnPage(j); k++) { triple[0] = i; triple[1] = j; triple[2] = k; NarrayRowUtil.RowPush(all_lines, triple); } } } Global.Debugf("info", "got {0} lines", all_lines.Dim(0)); // randomly permute it so that we train in random order if (randomize) { Shuffle(); } index = 0; }
/// <summary> /// Put image to last book and last page. /// Return new line number. /// </summary> public int PutNewImage(Bitmap bitmap) { int ibook = bookstores.Length() - 1; bool emptyBook = bookstores[ibook].NumberOfPages() <= 0; int ipage = emptyBook ? 0 : bookstores[ibook].NumberOfPages() - 1; int iline = emptyBook ? 0 : bookstores[ibook].LinesOnPage(ipage); // next line pos int lineid = iline == 0 ? 0 : bookstores[ibook].GetLineId(ipage, iline - 1) + 1; // next line id bookstores[ibook].AddLineId(ipage, lineid); // reserve position for line id bookstores[ibook].PutLine(bitmap, ipage, lineid); // put image to reserved position // update collection Intarray triple = new Intarray(3); triple[0] = ibook; triple[1] = ipage; triple[2] = iline; NarrayRowUtil.RowPush(all_lines, triple); // set current position bookno = ibook; pageno = ipage; lineno = lineid; return(lineid); }