In the ideal scenario, Tesseract will start working on data as soon as it can. For example, if you steam a filelist through stdin, we should start the OCR process as soon as the first filename is available. This is particularly useful when hooking Tesseract up to slow hardware such as a book scanning machine. Unfortunately there are tradeoffs. You can't seek on stdin. That makes automatic detecti
| 1078 | // identify the scenario that really matters: filelists on |
| 1079 | // stdin. We'll still do our best if the user likes pipes. |
| 1080 | bool TessBaseAPI::ProcessPagesInternal(const char* filename, |
| 1081 | const char* retry_config, |
| 1082 | int timeout_millisec, |
| 1083 | TessResultRenderer* renderer) { |
| 1084 | PERF_COUNT_START("ProcessPages") |
| 1085 | bool stdInput = !strcmp(filename, "stdin") || !strcmp(filename, "-"); |
| 1086 | if (stdInput) { |
| 1087 | #ifdef WIN32 |
| 1088 | if (_setmode(_fileno(stdin), _O_BINARY) == -1) |
| 1089 | tprintf("ERROR: cin to binary: %s", strerror(errno)); |
| 1090 | #endif // WIN32 |
| 1091 | } |
| 1092 | |
| 1093 | if (stream_filelist) { |
| 1094 | return ProcessPagesFileList(stdin, NULL, retry_config, |
| 1095 | timeout_millisec, renderer, |
| 1096 | tesseract_->tessedit_page_number); |
| 1097 | } |
| 1098 | |
| 1099 | // At this point we are officially in autodection territory. |
| 1100 | // That means any data in stdin must be buffered, to make it |
| 1101 | // seekable. |
| 1102 | std::string buf; |
| 1103 | const l_uint8 *data = NULL; |
| 1104 | if (stdInput) { |
| 1105 | buf.assign((std::istreambuf_iterator<char>(std::cin)), |
| 1106 | (std::istreambuf_iterator<char>())); |
| 1107 | data = reinterpret_cast<const l_uint8 *>(buf.data()); |
| 1108 | } |
| 1109 | |
| 1110 | // Here is our autodetection |
| 1111 | int format; |
| 1112 | int r = (stdInput) ? |
| 1113 | findFileFormatBuffer(data, &format) : |
| 1114 | findFileFormat(filename, &format); |
| 1115 | |
| 1116 | // Maybe we have a filelist |
| 1117 | if (r != 0 || format == IFF_UNKNOWN) { |
| 1118 | STRING s; |
| 1119 | if (stdInput) { |
| 1120 | s = buf.c_str(); |
| 1121 | } else { |
| 1122 | std::ifstream t(filename); |
| 1123 | std::string u((std::istreambuf_iterator<char>(t)), |
| 1124 | std::istreambuf_iterator<char>()); |
| 1125 | s = u.c_str(); |
| 1126 | } |
| 1127 | return ProcessPagesFileList(NULL, &s, retry_config, |
| 1128 | timeout_millisec, renderer, |
| 1129 | tesseract_->tessedit_page_number); |
| 1130 | } |
| 1131 | |
| 1132 | // Maybe we have a TIFF which is potentially multipage |
| 1133 | bool tiff = (format == IFF_TIFF || format == IFF_TIFF_PACKBITS || |
| 1134 | format == IFF_TIFF_RLE || format == IFF_TIFF_G3 || |
| 1135 | format == IFF_TIFF_G4 || format == IFF_TIFF_LZW || |
| 1136 | format == IFF_TIFF_ZIP); |
| 1137 |
nothing calls this directly
no test coverage detected