include prodmarkEngine prodmark include iostream include string includ

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <prodmarkEngine/prodmark.h>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <map>
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<std::vector<ProdmarkRect> > &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<ProdmarkDocumentZone> 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<std::string, ProdmarkEngine::ImageOrientation> 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] << " <path_to_image_file> <path_to_settings.json> [orientation]" << std::endl;
std::cout << "Orientation can be: ";
for (std::map<std::string, ProdmarkEngine::ImageOrientation>::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<std::string, ProdmarkEngine::ImageOrientation>::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<ProdmarkEngineInternalSettings> internalSettings(
ProdmarkEngineInternalSettings::createFromFilesystem(configPath));
ProdmarkEngineSessionSettings sessionSettings;
SampleStreamReporter reporter;
ProdmarkEngineSessionHelpers helpers;
ProdmarkEngine engine(*internalSettings);
freopen(lstFilePath.c_str(), "r", stdin);
std::vector<std::string> 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;
}