void clustering(string filename) { Mat image = imread(filename); Preprocessor* pr = new Preprocessor(image); pr->preprocess(10); Mat cover; if(!pr->warpObject()) { cout << "#WARP-UNSUCCESSFUL" << endl; cover = image.clone(); image.release(); Size newSize = (cover.size().width > cover.size().height) ? Size(1024, 768) : Size(768, 1024); resize(cover, cover, newSize); cout << "using the whole image..." << endl; } else { cover = pr->WarpedCover(); string nf = prependStringToFileName("to_swt_", filename); imwrite(nf, cover); cout << "#BEGIN-TO-SWT" << endl; cout << nf << endl; cout << "#END-TO-SWT" << endl; } cout << "#BEGIN-CLUSTERVECTOR" << endl; cout << Preprocessor::calculateLAB(40, cover) << endl; cout << "#END-CLUSTERVECTOR" << endl; }
void recognizing(string filename, vector<uint> ids) { Mat image = imread(filename); Recognizer* rcg = new Recognizer(0.70f, 0.065f); Preprocessor* pr = new Preprocessor(image); pr->preprocess(10); Mat cover; if(!pr->warpObject()) { cout << "#WARP-UNSUCCESSFUL" << endl; cover = image.clone(); image.release(); Size newSize = (cover.size().width > cover.size().height) ? Size(1024, 768) : Size(768, 1024); resize(cover, cover, newSize); cout << "using the whole image..." << endl; } else { cover = pr->WarpedCover(); } Mat trainingImage; for(size_t i = 0; i < ids.size(); ++i) { cout << "training " << i << endl; rcg->train(ids.at(i)); } if(rcg->recognize(Preprocessor::kuwaharaNagaoFilter(cover))) { Book result = rcg->LastResult(); cout << "#BEGIN-RESULT " << result.Id() << " #END-RESULT"; } else { cout << "#BEGIN-RESULT null #END-RESULT"; } cout << endl; }