CJocrPrimEX class reference manual

Table of contents
CJocrPrimEX subclass
  1. Overview
  2. ABSTRACTPARAMETER Structure
  3. Parameter Input/Output
  4. Parameter Adjustment Tool
  5. Parameter File Specification
  6. New Angle Estimation (Added on October 10, 2000)
  7. Dash Extraction (Added on July 31, 2002)
  8. Character Extraction Parameter Estimation (Added on July 31, 2002)

CJocrPrimEX Subclass Extension

This feature is an optional feature of the SDK.
It is a subclass of CJocrPrim that utilizes the
override (cluster extraction) feature and has a more powerful cluster extraction capability than the CJocrPrim class.
In terms of performance, it is capable of extracting with high accuracy by finely controlling the cluster extraction parameters.
Furthermore, it also includes features such as using parameters like area and centroid for extraction, distinguishing functions for text blocks, noise like dashed lines, and solid image areas like photographs.
Moreover, by specifying the extraction target area with a rectangle, it is possible to efficiently extract text from forms.
Due to its extensive parameters, it is designed to be used in combination with features like parameter input/output and parameter adjustment tool.
Table of Contents


1 Overview

To access this class, you will need the header files "absparam.h" and "cjocrprimex.h". Since it is a subclass of CJocrPrim class, all the functionalities of CJocrPrim class can be utilized. Additionally, the extended cluster extraction function is supported.
To use the extended cluster extraction function, it is necessary to set the extraction parameters using the
ABSTRACTPARAMETER structure. Although there are many data to be set in this structure, most of them are optional parameters and can be used more simply than cluster extraction in CJocrPrim class.
To fully utilize the functionality of the parameters, create valid parameters by testing the effects of the parameters using the parameter adjustment tool and save them as a parameter file.
Read and set the parameter file using the parameter input/output function.
The parameter file is in editable text format, but without a suitable parameter setting tool, it can be difficult to configure. Therefore, until you get used to it, use the parameter adjustment tool.
After setting the parameters, execute cluster extraction using the mabstractclusterfilter function described in the override (cluster extraction).
If you are using area information for extraction, you must calculate the area of all primitives using the mcalcfeaturepixel.
If you are using perimeter information for extraction, you must calculate both the area and perimeter of all primitives using the mcalcfeature.
Also, if you want to exclude clusters inside the background image, you must call the following statements after makeprim or makeprim8 and before mabstractclusterfilter:
// Detect background image
int        mregistbeta();
Return value:
0....Normal termination
Negative...Error
The processing before and after this statement is the same as the mabstractcluster function.
Table of Contents


3.2 ABSTRACTPARAMETER Structure

///////////////////////// // Cluster extraction parameters The parameters of the CJocrPrimEX class are set using the ABSTRACTPARAMETER structure defined in the header file absparam.h. The unit of the parameters is pixels. The difference due to resolution is adjusted by the ratio between the resolution at which the parameters are acquired, "parameter sampling dpi," and the actual document resolution.
There are only five required parameters, and the rest are optional parameters. Whether to enable optional parameters is specified by the bit flags in the "control flag".

Among these required parameters, the minimum distance must be set to 0 when dealing with kanji characters. This is because the distance between the primitives that make up a kanji character is 0.

When the extraction is not successful, start by removing all optional parameters. To identify the cause of unsuccessful extraction, turn on one optional parameter at a time.

typedef struct _ABSTRACTPARAMETER {
    int        mdpi;               // Parameter sampling dpi
    int        mcontrol;           // Control flag
// Primitive - Required
    int        minprimwidth;       // Minimum primitive width (Required)
    int        maxprimwidth;       // Maximum primitive width (Required)
    int        minprimheight;      // Minimum primitive height (Required)
    int        maxprimheight;      // Maximum primitive height (Required)
// Primitive - Optional
    double     minrate;            // Minimum height/width ratio of primitive (Optional)
    double     maxrate;            // Maximum height/width ratio of primitive (Optional)
    int        minpixel;           // Minimum area of primitive (Optional)
    int        maxpixel;           // Maximum area of primitive (Optional)
    int        minlength;          // Minimum perimeter of primitive (Optional)
    int        maxlength;          // Maximum perimeter of primitive (Optional)
// Distance between primitives
    // Either Euclidean distance or Manhattan distance
    double     mindist;            // Minimum Euclidean distance between primitives
    double     maxdist;            // Maximum Euclidean distance between primitives
    int        mindistx;           // Minimum distance along X coordinate in Manhattan distance
    int        maxdistx;           // Maximum distance along X coordinate in Manhattan distance
    int        mindisty;           // Minimum distance along Y coordinate in Manhattan distance
    int        maxdisty;           // Maximum distance along Y coordinate in Manhattan distance
// Cluster - Optional
    int        minclusterwidth;    // Minimum cluster width (Optional)
    int        maxclusterwidth;    // Maximum cluster width (Optional)
    int        minclusterheight;   // Minimum cluster height (Optional)
    int        maxclusterheight;   // Maximum cluster height (Optional)
    int        minnum;             // Minimum number of primitives inside a cluster (Optional)
    int        maxnum;             // Maximum number of primitives inside a cluster (Optional)
// Area where clusters exist (Optional)
    int        mleft;              // Top left X
    int        mtop;               // Top left Y
    int        mright;             // Bottom right X
    int        mbottom;            // Bottom right Y

// Added on October 10, 2000: minclusterarea~my4
// Minimum and maximum areas of clusters
    double    minclusterarea;      // Minimum cluster area
    double    maxclusterarea;      // Maximum cluster area
// Minimum and maximum ratios of primitive/cluster area
    double    minratecluster;      // Minimum ratio of primitive/cluster area
    double    maxratecluster;      // Maximum ratio of primitive/cluster area
// Area where clusters exist (diagonal rectangle: Optional)
// cw direction
    int        mx1;                // Bottom left X
    int        my1;                // Bottom left Y
    int        mx2;                // Top left X
    int        my2;                // Top left Y
    int        mx3;                // Top right X
    int        my3;                // Top right Y
    int        mx4;                // Bottom right X
    int        my4;                // Bottom right Y
} ABSTRACTPARAMETER;
The control flag has seven bit flags for whether to use optional parameters.

// Cluster extraction control
#define ABSTRACT_RATE 0x00000001 // Whether to use height/width information
#define ABSTRACT_PIXEL 0x00000002 // Whether to use area information
#define ABSTRACT_LENGTH 0x00000004 // Whether to use perimeter information
#define ABSTRACT_CLUSTERWIDTH 0x00000008 // Whether to use cluster width information
#define ABSTRACT_CLUSTERHEIGHT 0x00000010 // Whether to use cluster height information
#define ABSTRACT_NUM 0x00000020 // Whether to use number of clusters information
#define ABSTRACT_LOC 0x00000040 // Whether to use location information
Other flags are special, so I will explain each of them.
#define    ABSTRACT_SEPARATOR           0x00000080        // Whether to separate clusters by separator
#define    ABSTRACT_DIST                0x00000100        // Use Euclidean distance
#define    ABSTRACT_DISTXY              0x00000200        // Use city distance
#define    ABSTRACT_LONG                0x00000400        // Allow long primitives like "1" unconditionally
#define    ABSTRACT_FLAT                0x00000800        // Allow flat primitives like "ー" unconditionally
#define    ABSTRACT_SMALL               0x00001000        // Allow small primitives like "、" unconditionally
#define    ABSTRACT_1PRIM1CHAR1LINE     0x00002000        // 1 character = 1 primitive
                                                          // 1 line (public figure, land price map, table)
#define    ABSTRACT_1PRIM1CHAR1COLUMN   0x00004000        // 1 character = 1 primitive
                                                          // 1 column (rotated text in drawings)
#define    ABSTRACT_NOISE1              0x00008000        // Exclude clusters composed only of small primitives
                                                          // Dashed lines or noise
#define    ABSTRACT_NOISE2              0x00010000        // Exclude clusters within a solid graphic

// Added on October 10, 2000 - ABSTRACT_YOKOGAKI~ABSTRACT_NOISE3
#define    ABSTRACT_YOKOGAKI            0x00020000        // Horizontal writing specified in angle estimation
#define    ABSTRACT_TATEGAKI            0x00040000        // Vertical writing specified in angle estimation
#define    ABSTRACT_INFERANGLE          0x00080000        // Perform angle estimation
#define    ABSTRACT_LOC4                0x00100000        // Extract clusters only within diagonal rectangles
#define    ABSTRACT_CLUSTERAREA         0x00200000        // Whether to use cluster area information
#define    ABSTRACT_NOISE3              0x00400000        // Primitive bounding box area calculation / Cluster bounding box area calculation < 0.25
The sample extraction code is as follows:
#include    "cjocrprim.h"
#include    "absparam.h"
#include    "cjocrprimex.h"
#include    "errcode.h"
...
....
// Initialize the library by specifying a 20-digit code supplied by the licenser or the path of the license code file
CJocrPrimEX* pjocrprim = new CJocrPrimEX("ABCDEFGHJKLMNPQ23456");
// If using a license code path: CJocrPrim* prim = new CJocrPrim("C:\\Program Files\\Foo\\primitive.kcd");
pjocrprim->msetdocument(mdata,0,mwidth,mheight);      // Monochrome image with background as 0 and foreground as 1
ret = pjocrprim->msetdpi(400);                        // 400dpi
ret = pjocrprim->mcalcfeaturepixel();                 // Calculate area
ret = pjocrprim->mloadparameter("parameter.prm");     // Load parameter file
// Extract clusters
ret = pjocrprim->mabstractclusterfilter(0,1);         // Extended cluster extraction

delete pjocrprim;
...
Table of Contents


3.3 Parameter Input and Output

///////////////////
// Set Parameters
void    msetparameter(struct _ABSTRACTPARAMETER* parameter);
// Input
//        ABSTRACTPARAMETER* parameter;    cluster extraction parameter
/////////////////////////////
// Save Parameter File
int        msaveparameter(char* filename,struct _ABSTRACTPARAMETER* parameter);
// Saves the parameter file.
// The saved file can be edited as a text file.
// Input
//        char*                      filename;     parameter file name
// Output
//        struct _ABSTRACTPARAMETER* parameter;    cluster extraction parameter (memory allocation by the caller)
///////////////////////////////////////
// Load Parameters + Resolution Adjustment + Setup
int        mloadparameter(char* filename);
// Loads the parameter file, adjusts resolution, and sets up.
// Input
//        char*    filename;    parameter file name
//                              parameter file saved with msaveparameter
//                              parameter file saved with parameter adjustment tool
//                              file edited with text editor
/////////////////////////////
// Load Parameter File
int        mloadparameter(char* filename,struct _ABSTRACTPARAMETER* parameter);
// Loads the parameter file.
// Resolution adjustment and setup need to be called before performing cluster extraction.
// Input
//        char*                      filename;     parameter file name
// Output
//        struct _ABSTRACTPARAMETER* parameter;    cluster extraction parameter (memory allocation by the caller)

/////////////////////////
// Adjust Parameters for Resolution
void        madjustparameter(struct _ABSTRACTPARAMETER* parameter);
// Adjusts the values of the parameters to the resolution specified by msetdpi.
// Input
//        struct _ABSTRACTPARAMETER* parameter;    cluster extraction parameter
Parameters are loaded mainly from the parameter created with the parameter adjustment tool, adjusted for resolution, and then set. If you use mloadparameter/1, you don't need to call madjustparameter or msetparameter.

Table of Contents


3.4 Parameter Adjustment Tool

  • The parameter adjustment tool is used to interactively create a parameter file while checking the effects of the parameters.
    Table of Contents

    3.5 Parameter File Specification

    Sample parameter file
    Lines starting with "//" are comments and will be skipped.
    The first item is the version. Very old parameter files that do not have a version specified are not supported.
    // Version
    103

    The next item is the sampling resolution. The sampling resolution is the resolution when the parameters were obtained. To use parameters obtained at 400dpi with a different resolution such as 600dpi, call madjustparameter/1 to adjust the resolution.
    // Sampling resolution
    600

    The next item is the minimum and maximum values (in pixels) of the primitive width. In the example below, primitives with a width ranging from 4 to 27 pixels are adopted as elements of clusters.
    // Primitive width
    4-27

    The next item is the minimum and maximum values (in pixels) of the primitive height. In the example below, primitives with a height ranging from 19 to 26 pixels are adopted as elements of clusters.
    // Primitive height
    19-26

    The next item is the minimum and maximum values of the height/width ratio of the primitives. If it is less than 1.0, it is flatter than a square. If it is equal to 1.0, it is a square. If it is larger than 1.0, it is a thin "1" shape. In the example below, primitives with ratios ranging from 1.0 to 10.0 are adopted as elements of clusters.
    // Ratio
    1
    1.000000-10.000000

    The next item is a flag indicating whether to use the area of the primitives as a parameter, and the minimum and maximum values. A value of 1 indicates that the area information is used for clustering, and 0 indicates that it is not used. In the example below, the area information is used for clustering, with a minimum value of 75 square pixels and a maximum value of 237 square pixels.
    // Area
    1
    75-237

    The next item is a flag indicating whether to use the perimeter of the primitives as a parameter, and the minimum and maximum values. A value of 1 indicates that the perimeter information is used for clustering, and 0 indicates that it is not used. In the example below, the perimeter information is not used for clustering. The minimum value is 102 pixels and the maximum value is 178 pixels.
    // Perimeter
    0
    102-178

    The next item is a flag indicating whether to use the Euclidean distance (in pixels) as the distance between primitives that make up a cluster, and the minimum and maximum values. A value of 1 indicates the use of Euclidean distance, and 0 indicates not to use it. If the flag for Euclidean distance is 0, the city block distance is automatically used. In the example below, the Euclidean distance is not used for clustering. The minimum value for distance is 0 pixels and the maximum value is 16 pixels.
    // Euclidean distance
    0
    0.000000-16.000000

    The next item is the minimum and maximum values for the X-axis distance (in pixels) when using the city block distance (the distance parallel to the X-axis and Y-axis) as the distance between primitives that make up a cluster. If the flag for Euclidean distance is 0, the city block distance is automatically used. In this example, the minimum value for X-axis distance of the city block distance is 1 pixel and the maximum value is 30 pixels. The distance between two primitives that overlap on the X-axis is 0, so they will not belong to the same cluster according to this definition.
    // City block distance X
    1-30

    The following item is the minimum and maximum distance in the Y-axis when using the city distance (the distance parallel to the X and Y axes) in measuring the distance between primitives that make up the cluster. If the Euclidean distance flag is 0, the city distance will be automatically used. The minimum distance in the Y-axis for the city distance is 0 pixels, and the maximum distance is 0 pixels. With this definition, primitives that have a distance of 1 in the Y-axis will not be included in the same cluster.
    // City distance Y
    0-0

    The following item is a flag indicating whether the cluster width is used as a parameter or not, as well as the minimum and maximum values (in pixels). A 1 indicates that the cluster width is used for clustering, while a 0 indicates it is not used. In the example below, clusters outside the range of 39 pixels to 111 pixels in width will be discarded.
    // Cluster width
    1
    39-111

    The following item is a flag indicating whether the cluster height is used as a parameter or not, as well as the minimum and maximum values (in pixels). A 1 indicates that the cluster height is used for clustering, while a 0 indicates it is not used. In the example below, clusters outside the range of 19 pixels to 33 pixels in height will be discarded.
    // Cluster height
    1
    19-33

    The following item is a flag indicating whether the number of primitives that make up the cluster is used as a parameter or not, as well as the minimum and maximum values. A 1 indicates that the number of primitives is used for clustering, while a 0 indicates it is not used. In the example below, clusters will be discarded if the number of primitives is less than 3 or greater than 10.
    // Number of primitives in the cluster
    1
    3-10

    The following item is a flag indicating whether the rectangular area where the cluster exists is used as a parameter or not, as well as the coordinates of the top left and bottom right of the rectangle. A 1 indicates that the area is used for clustering, while a 0 indicates it is not used. In the example below, the area is not used as a parameter.
    // Cluster area
    0
    (0,0)-(0,0)

    1... If there are primitives that do not belong to the cluster between two primitives, it is determined that the two primitives belong to different clusters.
    // Separator processing
    1

    1... Long and thin primitives like "1" and "I" are accepted unconditionally.
    // Exception processing for long and thin characters
    0

    1... Flat primitives like "ー" and "一" are accepted unconditionally.
    // Exception processing for flat characters
    0

    1... Small primitives like "、" and "・" are accepted unconditionally.
    // Exception processing for small characters
    1

    1... If 1 primitive = 1 character (numeric, alphanumeric, comma, period, hyphen, etc.), set to 1 for improved accuracy.
    // 1 primitive 1 character 1 line
    1

    1... If 1 primitive = 1 character (numeric, alphanumeric, comma, period, hyphen, etc.), set to 1 for improved accuracy.
    // 1 primitive 1 character 1 column
    0

    1... Clusters composed only of tiny primitives will be discarded.
    // Noise 1
    1

    1... Automatically determine and discard clusters that appear to be photographs.
    // Noise 2
    1

    1... All clusters are horizontal writing. They are not used specifically for clustering and can be freely set by library users.
    // Horizontal writing
    1

    1... All clusters are vertical writing. They are not used specifically for clustering and can be freely set by library users.
    // Vertical writing
    0

    1... Angle estimation will be performed because the cluster contains oblique clusters.
    // Angle estimation
    0

    The following item indicates whether to use the arbitrary rectangular region where the cluster exists as a parameter, and the coordinates of the top left and bottom right of the rectangle. 1 indicates that the region is used for clustering, and 0 indicates that it is not used. In the example below, the region is not used as a parameter.
    // Arbitrary rectangular region
    0
    (0,0)-(0,0)-(0,0)-(0,0)

    The following item indicates whether to use the area of the cluster, and the minimum and maximum area values. However, as of October 10, 2000, they are ignored.
    // Cluster area
    0
    0.000000-10000000000000000.000000

    The following item indicates whether to use the total area of the primitive / cluster as a flag. However, as of October 10, 2000, they are ignored.
    // Noise 3
    0
    Table of Contents


    3.6 New Angle Estimation

    Table of Contents

    We estimate the angle of the cluster when considering the extracted cluster as paragraphs of text. This is a high-precision version using the advanced features of CJocrPrimEX.
    The angle is in radians and is positive clockwise when the y-axis is downwards, and positive counterclockwise when the y-axis is upwards.
    // Calculation of cluster angle estimation
        void mcalcangle(CLUSTER* pcluster,double& angle,int fusionflag = 1);
        Input:
            CLUSTER*    pcluster;       Cluster (obtained from mgetvalidcluster)
            int         fusionflag;     Normally no need to specify.
                                       Set to 0 for improved accuracy if it is guaranteed that
                                       one primitive = one character (uppercase letters, numbers, commas, etc.)
                                       Default value is 1.
        Output:
            double&     angle;          Estimated angle (in radians)
    
    Table of Contents


    3.7 Dashed Line Extraction

    Table of Contents

    Extract dashed lines.
    Extract dashed line primitives using cluster extraction parameters and common specifications.
    As a specific parameter for dashed lines, there is the maximum angle formed by two adjacent line segments of the dashed line.
    // Dashed line recognition
    // Input
    //  char*       parameterfilename;  Dashed line extraction parameter file name (same as cluster extraction parameters)
    //                                  Note that the minimum number of primitives that make up a cluster must be 5-6 or higher for dashed line extraction to be possible
    //  double      angle;              Maximum angle formed by two adjacent line segments of the dashed line (0 to π / 2 radians)
    //                                  In the case of (x1,y1)-(x2,y2)-(x3,y3), it is the angle formed by vectors (x1,y1)-(x2,y2) and (x2,y2)-(x3,y3)
    //  int         from;               Extract dashed lines starting from layer "from"
    //  int         to;                 Move the extracted dashed lines to layer "to"
    // Return value
    //  0....Normal termination
    //  Negative...Error
    int             movedotline(char* parameterfilename,double angle,int from,int to);
    
    Table of Contents


    3.8 Estimating Character Extraction Parameters

    Table of Contents

    Estimate the parameters for extracting strings from the current document image automatically. The accuracy is reasonable as it is estimated from the frequency distribution table of the size of primitives.

    // Estimate character points
    // Estimate the size of characters in the current document (as this is a statistical estimation, do not accept it blindly)
    // Input
    //  int                 layer = 0;          // Estimate from the images belonging to this layer
    //                                          // If it is -1, estimate from all layers
    //  int                 amaxpoint = 36;     // Consider primitives up to the size specified by amaxpoint as characters
    //  double              lowrate = 0.01;     // Exclude primitives from the bottom up to lowrate in the frequency distribution table
    //  double              highrate = 0.01;    // Exclude primitives from the top down to highrate in the frequency distribution table
    // Output
    //  ABSTRACTPARAMETER*  parameter;          // Buffer to store the estimated parameters
    void                    minferparameter(ABSTRACTPARAMETER* parameter,int layer = 0,int amaxpoint = 36,double lowrate = 0.01,double highrate = 0.01);
    
    Table of Contents


    manual homepage

    user's manual