CJocrPrimRD class reference manual

Table of Contents
CJocrPrimRD subclass extention
  1. New Angle Estimation (Added on October 10, 2000)

Extension Subclass CJocrPrimRD

This feature is an optional feature of the SDK.
It is a subclass of CJocrPrimEX. In addition to all the functionalities of the CJocrPrim and CJocrPrimEX classes, it provides new functionalities through a combination of raster-vector conversion and vector-raster conversion libraries.
As of October 10, 2000, the only available functionality is the improvement in angle estimation by converting grid lines to raster vectors.
In the future, we plan to add functionalities such as cluster extraction within polygon polygons and conversion of character vectors to raster.
Table of Contents


1 New Angle Estimation


Table of Contents

Estimate the angle of the cluster when considering the extracted clusters as paragraphs of text.
Extract partition lines from the image and use the angle of line segments near the cluster as a clue for angle estimation of the cluster.
The angle is expressed in radians, where clockwise is positive when the y-axis direction is downwards, and counterclockwise is positive when the y-axis direction is upwards.
// Calculate the angle estimation of the cluster
    void mcalcangle(CLUSTER* pcluster, double& angle, int fusionflag = 1);
    Input:
        CLUSTER*    pcluster;       Cluster (acquired using mgetvalidcluster)
        int         fusionflag;     Usually no need to specify.
                                  If one primitive equals one character (capital alphabet, number, comma, etc.)
                                  and this is guaranteed, setting it to 0 will improve accuracy.
                                  Default value is 1.
    Output:
        double&     angle;          Estimated angle (in radians)
Vectorization of partition lines
When using the partition lines for angle estimation, mvectorizeline must be called between makeprim and mcalcangle.
Also, before mvectorize, the resolution of the current image needs to be set using msetdpi/1.
Vectorization is performed with the following algorithm:
  1. Pick up up to 72 points (up to N ~ N pixels for Ndpi) within 72 points
  2. Backward transform the picked primitives
  3. Vectorize the contour lines of the transformed image (for lines, vectorize only one side)
  4. Calculate and store position and angle information of line segments with a certain length
If vectorization is not completed, CJocrPrimRD::mcalcangle behaves the same as CJocrPrimEX::mcalcangle.
// Call mvectorizeline function to perform vectorization
// By default, vectorization is disabled, so if you want to use partition lines, call this function at least once
// It can be called multiple times without problems
    void menablevectorize();
// Do not call mvectorizeline function to perform vectorization
// Partition line information is not used for angle estimation either
// It can be called multiple times without problems
    void mdisablevectorize();
// Vectorize partition lines
    int mvectorizeline();
    Return value         0...Normal completion (including the case where vectorization is not performed by mdisablevectorize)
                       Negative...Error
Sample Code
#include    "ocrdef.h"
#include    "ocrco.h"
#include    "cjocrprimrd.h"
#include    "errcode.h"
...
....
// Initialize the library by specifying a 20-digit code supplied by the licenser or the path to a license code file
CJocrPrimRD* pjocrprim = new CJocrPrimRD("ABCDEFGHJKLMNPQ23456");
// If using a license code path, use CJocrPrim* prim = new CJocrPrim("C:\\Program Files\\Foo\\primitive.kcd");
pjocrprim->msetdocument(mdata,0,mwidth,mheight);      // Monochrome image with background 0 and foreground 1
pjocrprm->msetdpi(400);
ret = pjocrprim->makeprim();
if(ret < 0) {
    Error;
}
///////////////////////
// Vectorization of rectangular lines
pjocrprim->menablevectorize();
ret = pjocrprim->mvectorizeline();
if(ret < 0) {
    Error;
}
// Extract clusters (primitives belonging to clusters are moved to layer 1)
ret = pjocrprim->mabstractcluster(0,1);
if(ret < 0) {
    Error;
}
// Get the number of clusters
int clusternum = pjocrprim->mgetvalidclusternum();
CLUSTER* pcluster = (CLUSTER*)malloc(sizeof(CLUSTER) * clusternum);
if(pcluster) {
    // Get clusters
    mgetvalidcluster(pcluster);
    for(int i = 0 ; i < clusternum ; i++) {
        double    angle;
		// The information of rectangular lines is used for angle estimation
        pjocrprim->mcalcangle(pcluster + i,angle);  // angle is the estimated angle (in radians)
                                                    // The actual baseline angle is either angle or angle+/2
        ....
        ...
    }
}
delete pjocrprim;
...
Table of Contents



manual homepage

user's manual