Leptonica  1.54
Файл src/regutils.c
#include <string.h>
#include "allheaders.h"

Функции

static char * getRootNameFromArgv0 (const char *argv0)
l_int32 regTestSetup (l_int32 argc, char **argv, L_REGPARAMS **prp)
l_int32 regTestCleanup (L_REGPARAMS *rp)
l_int32 regTestCompareValues (L_REGPARAMS *rp, l_float32 val1, l_float32 val2, l_float32 delta)
l_int32 regTestCompareStrings (L_REGPARAMS *rp, l_uint8 *string1, size_t bytes1, l_uint8 *string2, size_t bytes2)
l_int32 regTestComparePix (L_REGPARAMS *rp, PIX *pix1, PIX *pix2)
l_int32 regTestCompareSimilarPix (L_REGPARAMS *rp, PIX *pix1, PIX *pix2, l_int32 mindiff, l_float32 maxfract, l_int32 printstats)
l_int32 regTestCheckFile (L_REGPARAMS *rp, const char *localname)
l_int32 regTestCompareFiles (L_REGPARAMS *rp, l_int32 index1, l_int32 index2)
l_int32 regTestWritePixAndCheck (L_REGPARAMS *rp, PIX *pix, l_int32 format)

Переменные

l_int32 NumImageFileFormatExtensions
const char * ImageFileFormatExtensions []

Функции

static char * getRootNameFromArgv0 ( const char *  argv0) [static]

getRootNameFromArgv0()

Input: argv0 Return: root name (without the '_reg'), or null on error

Notes: (1) For example, from psioseg_reg, we want to extract just 'psioseg' as the root. (2) In unix with autotools, the executable is not X, but ./.libs/lt-X. So in addition to stripping out the last 4 characters of the tail, we have to check for the '-' and strip out the "lt-" prefix if we find it.

l_int32 regTestCheckFile ( L_REGPARAMS rp,
const char *  localname 
)

regTestCheckFile()

Input: rp (regtest parameters) localname (name of output file from reg test) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

Notes: (1) This function does one of three things, depending on the mode: * "generate": makes a "golden" file as a copy . * "compare": compares contents with the golden file * "display": makes the file but does no comparison (2) The canonical format of the golden filenames is: /tmp/lept/golden/<root of="" main="" name>="">_golden.<index>. <ext of="" localname>=""> e.g., /tmp/lept/golden/maze_golden.0.png It is important to add an extension to the local name, because the extension is added to the name of the golden file.

regTestCleanup()

Input: rp (regression test parameters) Return: 0 if OK, 1 on error

Notes: (1) This copies anything written to the temporary file to the output file /tmp/lept/reg_results.txt.

l_int32 regTestCompareFiles ( L_REGPARAMS rp,
l_int32  index1,
l_int32  index2 
)

regTestCompareFiles()

Input: rp (regtest parameters) index1 (of one output file from reg test) index2 (of another output file from reg test) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

Notes: (1) This only does something in "compare" mode. (2) The canonical format of the golden filenames is: /tmp/lept/golden/<root of="" main="" name>="">_golden.<index>. <ext of="" localname>=""> e.g., /tmp/lept/golden/maze_golden.0.png

l_int32 regTestComparePix ( L_REGPARAMS rp,
PIX pix1,
PIX pix2 
)

regTestComparePix()

Input: rp (regtest parameters) pix1, pix2 (to be tested for equality) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

Notes: (1) This function compares two pix for equality. On failure, this writes to stderr.

l_int32 regTestCompareSimilarPix ( L_REGPARAMS rp,
PIX pix1,
PIX pix2,
l_int32  mindiff,
l_float32  maxfract,
l_int32  printstats 
)

regTestCompareSimilarPix()

Input: rp (regtest parameters) pix1, pix2 (to be tested for near equality) mindiff (minimum pixel difference to be counted; > 0) maxfract (maximum fraction of pixels allowed to have diff greater than or equal to mindiff) printstats (use 1 to print normalized histogram to stderr) Return: 0 if OK, 1 on error (a failure in similarity comparison is not an error)

Notes: (1) This function compares two pix for near equality. On failure, this writes to stderr. (2) The pix are similar if the fraction of non-conforming pixels does not exceed . Pixels are non-conforming if the difference in pixel values equals or exceeds . Typical values might be = 15 and = 0.01. (3) The input images must have the same size and depth. The pixels for comparison are typically subsampled from the images. (4) Normally, use = 0. In debugging mode, to see the relation between and the minimum value of for success, set this to 1.

l_int32 regTestCompareStrings ( L_REGPARAMS rp,
l_uint8 string1,
size_t  bytes1,
l_uint8 string2,
size_t  bytes2 
)

regTestCompareStrings()

Input: rp (regtest parameters) string1 (typ. the expected string) bytes1 (size of string1) string2 (typ. the computed string) bytes2 (size of string2) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

l_int32 regTestCompareValues ( L_REGPARAMS rp,
l_float32  val1,
l_float32  val2,
l_float32  delta 
)

regTestCompareValues()

Input: rp (regtest parameters) val1 (typ. the golden value) val2 (typ. the value computed) delta (allowed max absolute difference) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

l_int32 regTestSetup ( l_int32  argc,
char **  argv,
L_REGPARAMS **  prp 
)

regTestSetup()

Input: argc (from invocation; can be either 1 or 2) argv (to regtest: [1] is one of these: "generate", "compare", "display") &rp (<return> all regression params) Return: 0 if OK, 1 on error

Notes: (1) Call this function with the args to the reg test. The first arg is the name of the reg test. There are three cases: Case 1: There is either only one arg, or the second arg is "compare". This is the mode in which you run a regression test (or a set of them), looking for failures and logging the results to a file. The output, which includes logging of all reg test failures plus a SUCCESS or FAILURE summary for each test, is appended to the file "/tmp/lept/reg_results.txt. For this case, as in Case 2, the display field in rp is set to FALSE, preventing image display. Case 2: The second arg is "generate". This will cause generation of new golden files for the reg test. The results of the reg test are not recorded, and the display field in rp is set to FALSE. Case 3: The second arg is "display". The test will run and files will be written. Comparisons with golden files will not be carried out, so the only notion of success or failure is with tests that do not involve golden files. The display field in rp is TRUE, and this is used by pixDisplayWithTitle(). (2) See regutils.h for examples of usage.

l_int32 regTestWritePixAndCheck ( L_REGPARAMS rp,
PIX pix,
l_int32  format 
)

regTestWritePixAndCheck()

Input: rp (regtest parameters) pix (to be written) format (of output pix) Return: 0 if OK, 1 on error (a failure in comparison is not an error)

Notes: (1) This function makes it easy to write the pix in a numbered sequence of files, and either to: (a) write the golden file ("generate" arg to regression test) (b) make a local file and "compare" with the golden file (c) make a local file and "display" the results (3) The canonical format of the local filename is: /tmp/lept/regout/<root of="" main="" name>="">.<count>.<format extension>=""> e.g., for scale_reg, /tmp/lept/regout/scale.0.png


Переменные