#include #include #include #include #include #include std::ostream &operator<<(std::ostream &ostr, ProdmarkRect rect) { ostr << " (" << rect.getX() << ", " << rect.getY() << ", " << rect.getWidth() << ", " << rect.getHeight() << ") "; return ostr; } class SampleStreamReporter : public ProdmarkStreamReporterInterface { public: void SnapshotProcessed(const ProdmarkResult &result, bool may_finish) { std::cout << "Snapshot has been processed, may_finish is: " << std::boolalpha << may_finish << std::endl; printResult(result); std::cout << std::endl; } void SnapshotRejected() { std::cout << "Snapshot has been rejected" << std::endl; } void SymbolRectsFound(const std::vector > &rects) { std::cout << "Symbol rects found, first is at " << rects[0][0] << std::endl; } private: void printResult(const ProdmarkResult &result) { ::printf("Document type: %s\n", result.getDocType().getAsString().c_str()); const std::vector zones = result.getDocZones(); for (int i = 0; i < zones.size(); ++i) { ::printf("serial: %d: \"%s\"\n", i, zones[i].getZoneSerial().getAsString().c_str()); ::printf("row: %d: \"%s\"\n", i, zones[i].getZoneRow().getAsString().c_str()); ::printf("place: %d: \"%s\"\n", i, zones[i].getZonePlace().getAsString().c_str()); } } }; int main(int argc, char **argv) { std::string imageDirPath; std::string configPath; std::string lstFilePath; ProdmarkEngine::ImageOrientation imageOrientation = ProdmarkEngine::Landscape; std::map orientations; orientations["landscape"] = ProdmarkEngine::Landscape; orientations["portrait"] = ProdmarkEngine::Portrait; orientations["inverted_landscape"] = ProdmarkEngine::InvertedLandscape; orientations["inverted_portrait"] = ProdmarkEngine::InvertedPortrait; if(argc != 4 && argc != 5) { std::cout << "Usage: " << argv[0] << " [orientation]" << std::endl; std::cout << "Orientation can be: "; for (std::map::const_iterator it = orientations.begin(); it != orientations.end(); ++it) { std::cout << it->first << ((it->second == imageOrientation) ? " (default)" : "") << " "; } std::cout << std::endl; return 1; } else { imageDirPath = argv[1]; configPath = argv[2]; lstFilePath = argv[3]; if (argc == 5) { const std::string orientationString = argv[4]; const std::map::const_iterator it = orientations.find(orientationString); if (it == orientations.end()) { std::cout << "Error! No such orientation: " << orientationString << std::endl; return 2; } else { imageOrientation = it->second; } } } std::auto_ptr internalSettings( ProdmarkEngineInternalSettings::createFromFilesystem(configPath)); ProdmarkEngineSessionSettings sessionSettings; SampleStreamReporter reporter; ProdmarkEngineSessionHelpers helpers; ProdmarkEngine engine(*internalSettings); freopen(lstFilePath.c_str(), "r", stdin); std::vector images(0); std::string cur_name = ""; while(std::getline(std::cin, cur_name)) { images.push_back(cur_name); } try { engine.InitializeSession(&reporter, &helpers, &sessionSettings); for (int i = 0; i < images.size(); ++i) { engine.FeedImageFile(imageDirPath + "\\" + images[i], imageOrientation); } engine.TerminateSession(); } catch(ProdmarkException &e) { std::cout << "Something goes wrong: " << e.what() << std::endl; return 1; } return 0; }