开发者

C++ program snippet: what is this doing?

I'm trying to figure out how to output hOCR using Tesseract. Documentation is limited, so I am looking into the code. I found this in the main() function:

bool output_hocr = tessedit_create_hocr;
outfile = argv[2];
outfile += output_hocr ? ".html" : tessedit_create_boxfile ? ".box" : ".txt";

A typical command for Tesseract is this: tesseract input.tif output_file.txt (the output file will be appended with another .txt in this example). main()'s signature is int main开发者_C百科(int argc, char **argv).

What exactly is the code snippet doing?


It's generating the output filename.

bool output_hocr = tessedit_create_hocr;

Saves the tessedit_create_hocr flag in a locally scoped variable.

outfile = argv[2];

Initializes the outfile variable with the base filename from the command line. Something like "Scann0000.tif".

outfile += output_hocr ? ".html" : tessedit_create_boxfile ? ".box" : ".txt";

Appends the appropriate extension based on flags. Could be re-written as

if( ouput_hocr )
    outfile += ".html";
else if( tessedit_create_boxfile )
    outfile += ".box";
else
    outfile += ".txt";


It's taking a base filename from the second command-line argument (output_file.txt in your example) then choosing the extension with the ternary operator.

If output_hocr, ".html"

Otherwise, if tessedit_create, ".box"

Otherwise, ".txt"

Note that this is C++.


If the output_hocr variable is true it appends ".html" to outfile.

If it is false it checks tessedit_create_boxfile if it is true, it appends ".box" to outfile, otherwise it appends ".txt".


This code is just deciding what file extension to give outfile based on the value of tessedit_create_hocr (it is unclear how or where this variable is initialized given the code snippet provided).

If the value is true, the program will name the output file ".html". Otherwise, it will be ".box" or ".txt", depending on the value of tessedit_create_boxfile (it is also unclear where this is initialized).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜