// Detect background image int mregistbeta(); Return value: 0....Normal termination Negative...ErrorThe processing before and after this statement is the same as the mabstractcluster function.
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 informationOther 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.25The 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; ...
/////////////////// // 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 parameterParameters 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.
// Version 103 |
// Sampling resolution 600 |
// Primitive width 4-27 |
// Primitive height 19-26 |
// Ratio 1 1.000000-10.000000 |
// Area 1 75-237 |
// Perimeter 0 102-178 |
// Euclidean distance 0 0.000000-16.000000 |
// City block distance X 1-30 |
// City distance Y 0-0 |
// Cluster width 1 39-111 |
// Cluster height 1 19-33 |
// Number of primitives in the cluster 1 3-10 |
// Cluster area 0 (0,0)-(0,0) |
// Separator processing 1 |
// Exception processing for long and thin characters 0 |
// Exception processing for flat characters 0 |
// Exception processing for small characters 1 |
// 1 primitive 1 character 1 line 1 |
// 1 primitive 1 character 1 column 0 |
// Noise 1 1 |
// Noise 2 1 |
// Horizontal writing 1 |
// Vertical writing 0 |
// Angle estimation 0 |
// Arbitrary rectangular region 0 (0,0)-(0,0)-(0,0)-(0,0) |
// Cluster area 0 0.000000-10000000000000000.000000 |
// Noise 3 0 |
// 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)
// 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);
// 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);