Recognition Method for Deep Learning Compatible Version
The following improvements have been made.
Note that the deep learning parameters are assumed to be in the same folder as the old OCR engine's system dictionary.
Additionally, even when using only deep learning-supported recognition, the old OCR dictionary is still required for registration in the language dictionary and user pattern dictionary.
  1. Hybrid Recognition with the Old Engine and Deep Learning-Supported Engine
  2. Hybrid recognition is performed based on flag specification.
    You can use the user pattern dictionary that you have registered during the previous operation.
  3. Deep Learning-Supported Engine Recognition
  4. The old OCR engine is not used.
    You cannot use the user pattern dictionary that you have registered during the previous operation.
  5. Deep Learning-Supported Language Processing (Scheduled for release in the first quarter of 2023)
  6. Language processing of the old OCR engine can still be used.
    It can be used for recognition with the old OCR engine without deep learning, or for hybrid recognition with the old engine.
  7. Grayscale-Supported Recognition
  8. You can set grayscale documents using the msetdocument8() method.
    It is recommended to set grayscale or color documents when using deep learning-supported recognition.
    Deep learning-supported recognition can also be used with monochrome binary images.
  9. Color Image-Supported Recognition
  10. You can set 24-bit color documents using the msetdocument24() method.
    It is recommended to set grayscale or color documents when using deep learning-supported recognition.


  1. Hybrid Recognition
  2. Set BLOCK_DNNASSIST using msetsprecognizeflag2 in the CJocrBlock class.
    First, recognition is performed using the old OCR engine, and if the confidence level of the top candidate result exceeds the value set with msetminscore, the result of the old OCR engine is used as it is.
    If the confidence level is below msetminscore, it is re-recognized using deep learning and the result is used.
    If msetminscore API is not set, the confidence level for re-recognition is set to 90. If it is increased above 90, the use of the old OCR engine's result decreases and the use of the deep learning engine's result increases.
    Also, since the old OCR engine is faster, if it is increased above 90, the recognition speed becomes slower. Accuracy improves as the deep learning engine has higher accuracy.
    If it is decreased below 90, the use of the old OCR engine's result increases, the use of the deep learning engine's result decreases, and the recognition speed becomes faster, but the accuracy decreases.
  3. Recognition with Deep Learning-Supported Engine Only
  4. Set BLOCK_DNNONLY using msetsprecognizeflag2 in the CJocrBlock class. All recognition is performed using deep learning, and the result is used.
After setting msetsprecognizeflag2 to use deep learning, use msetdocument/msetdocument8/msetdocument24 to set the document. Grayscale document is required for deep learning recognition.
If a monochrome binary document is set with msetdocument, a grayscale document will be generated internally in the CJocrBlock class.
If a color document is set with msetdocument24, a grayscale document will also be generated internally in the CJocrBlock class.
Additionally, when using the old OCR engine, a monochrome binary image is required, so if msetdocument8/msetdocument24 is used, a monochrome binary image will be generated from the grayscale document.

	// Set flag (because msetsprecognizeflag/mgetsprecognizeflag overflowed)
	// Input
    //    int		flag;			// ( in)flag    BLOCK_TATEGAKIGYU(cjocrblock.h)
	//                              //              BLOCK_DNNONLY(ocrdef.h)				Recognize only with deep learning engine
	//                              //              BLOCK_DNNASSIST(ocrdef.h)			Recognize with old engine first. Only recognize with deep learning engine for low confidence characters
	void			msetsprecognizeflag2(int flag = 0) {msprecognizeflag2 = flag;}
	int				mgetsprecognizeflag2() {return msprecognizeflag2;}
	// Set threshold to switch between deep learning engine and old engine
	// int			score;			// ( in)score   If BLOCK_DNNASSIST, recognize only if confidence is below score
                                    //              Recommended range for score is around 75-95 (default value is 85)
	void			msetmindnnscore(int score)
	{
		mindnnscore = score;
	}
	// Get threshold to switch between deep learning engine and old engine (only for BLOCK_DNNASSIST)
	int				mgetmindnnscore() {return mindnnscore;}
    
    // Note: msetdocument8/msetdocument24 must be called after setting BLOCK_DNNONLY/BLOCK_DNNASSIST
	// unsigned char*	pdata;			// ( in)1 pixel 8bit grayscale image buffer
	//   pdata is allocated by the calling side (application side). It must not be deallocated until the entire process is completed
	// int				width;			// ( in)image width (in pixels)
	// int				scanlinesize;	// ( in)byte size of one line of the image (in bytes)
	// int				height;			// ( in)image height (in pixels)
	// Return value
	//  0.....Normal completion
	//  Negative....Error code (refer to errcode.h for error types)
	int					msetdocument8(unsigned char* pdata,int width,int scanlinesize,int height);

	// unsigned char*	pdata;			// ( in)1 pixel 24bit color image buffer
	//   pdata is allocated by the calling side (application side). It must not be deallocated until the entire process is completed
	// int				width;			// ( in)image width (in pixels)
	// int				scanlinesize;	// ( in)byte size of one line of the image (in bytes)
	// int				height;			// ( in)image height (in pixels)
	// Return value
	//  0.....Normal completion
	//  Negative....Error code (refer to errcode.h for error types)
	int					msetdocument24(unsigned char* pdata,int width,int scanlinesize,int height);


Example
#include "ocrdef.h"
#include "ocrco.h"
#include "cjocrstock.h"
#include "cjocrdict98.h"
#include "cjocrpat98.h"
#include "cjocrrec98.h"
#include "cjocrline98.h"
#include "cjocrlang.h"
#include "cjocrblock.h"
#include "errcode.h"
...
....
// Create pattern class
CJocrPattern* pattern = new CJocrPattern;
int ret = pattern->mallocmemory();
if (ret < 0) {
	printf("Pattern class memory allocation error");
	delete pattern;
	exit(1);
}
// Create dictionary class
CJocrDict* pjocrdict = new CJocrDict;
// The parameters for deep learning are assumed to be stored in the same folder as the system dictionary
pjocrdict->msetsystemdict("c:\\dic\\feature\\system");
pjocrdict->msetsystemdict("c:\\dic\\feature\\systemfat");
pjocrdict->msetuserdict("c:\\dic\\feature\\user");
ret = pjocrdict->mloaddict();
if (ret < 0) {
	printf("Error");
	delete pjocrdict;
	delete pattern;
	exit(1);
}
// Create single character recognition class
CJocrRecognize* precognize = new CJocrRecognize;
precognize->msetpatter(pattern);
precognize->msetdict(pjocrdict);
// Initialize single character recognition class
ret = precognize->mallocmemory();
if (ret < 0) {
	printf("Error");
	delete precognize;
	delete pjocrdict;
	delete pattern;
	exit(1);
}
// Create line recognition class with language processing
CJocrLang* pjocrlang = new CJocrLang;
pjocrlang->msetpatter(pattern);
pjocrlang->msetrecognize(precognize);
// Create block recognition class
CJocrBlock* pjocrblock = new CJocrBlock;
pjocrblock->msetlang(pjocrlang);
pjocrblock->msetprocess(PREPROCESS_INSIDE);	// Exclude primitives that touch the frame

// --------- Deep learning support starts here ------------
pjocrblock->msetsprecognizeflag2(pjocrblock->mgetsprecognizeflag2() | BLOCK_DNNASSIST);         // Hybrid recognition
// pjocrblock->msetsprecognizeflag2(pjocrblock->mgetsprecognizeflag2() | BLOCK_DNNONLY);        // Use only deep learning for recognition

// Set thresholds to switch between deep learning and old engine
// int score; (in) score Only recognize with deep learning engine if the confidence is below score for BLOCK_DNNASSIST (default value is 85)
pjocrblock->msetmindnnscore(80);

// pjocrblock->msetgray2monoparameter(0, 64, 80.0);      // If performing binarization in the application (pjocrblock->msetdocument(pdata, mwidth, mheight) is required later), the second and third arguments can be arbitrary
// pjocrblock->msetgray2monoparameter(1, 64, 80.0);      // The default value, if binarization is performed using Otsu's method internally in the library, the second and third arguments can be arbitrary
pjocrblock->msetgray2monoparameter(2, 64, 80.0);      // If performing shading correction binarization internally in the library
// Set the document
pjocrblock->msetdocument8(mgraydata, mwidth, mgrayscanlinesize, mheight);          // For 8-bit grayscale images
// pjocrblock->msetdocument24(mgraydata, mwidth, mgrayscanlinesize, mheight);      // For 24-bit color images
// --------- Deep learning support ends here ------------

// Set the document
// pjocrblock->msetdocument(mdata, mwidth, mheight);     // Uncomment if using a binarized image created in the application
pjocrblock->msetdpi(400);		// Resolution 400dpi
// Set the paragraph
// Set the block
OCRBlock ocrblock;
ocrblock.baseline.x1 = 100;
ocrblock.baseline.y1 = 100;
ocrblock.baseline.x2 = 300;
ocrblock.baseline.y2 = 200;
ocrblock.thickness = 100;
// Baseline is (100,100)-(300,200)
// Line height is 100
// Background 0
// Set a block for horizontal writing
pjocrblock->msetblock(ocrblock, atan2(ocrblock.baseline.y2 - ocrblock.baseline.y1, ocrblock.baseline.x2 - ocrblock.baseline.x1), 0, 0);
// Create normalized images
ret = pjocrblock->mregularize();
if (ret < 0) {
	printf("Error");
	delete pjocrblock;
	delete pjocrlang;
	delete precognize;
	delete pjocrdict;
	delete pattern;
	exit(1);
}
// Recognize the paragraph
pjocrblock->msetunderlineflag(1);							// Perform underline processing
ret = pjocrblock->mrecognizecluster(CHAR_SET_ALL, 0);		// Recognize all character types
if (ret < 0) {
	printf("Error");
	delete pjocrblock;
	delete pjocrlang;
	delete precognize;
	delete pjocrdict;
	delete pattern;
	exit(1);
}

// Get recognition results
int resultnum;
mgetresult(resultnum, NULL);
// Allocate a buffer of size result * sizeof(OCRResult)
OCRResult* pocrresult = malloc(sizeof(OCRResult) * resultnum);
if (pocrresult) {
	pjocrblock->mgetresult(resultnum, pocrresult);
}
// pocrresult[i].cand[0].code contains the recognition results of each character or
// the line break codes 0x0d,0x0a as line separators.
....
...
..
delete pjocrblock;
delete pjocrlang;
delete precognize;
delete pjocrdict;
delete pattern;