| |
|
| OpenRTK™ 7.0 Tutorial |
| |
(for Win32 & Win64)
OpenRTK™ 7.0 is a powerful OCR toolkit for Win32 & Win64 developers. It has more than 100 APIs that are well-defined for easy integration. The following instructions will help you write your first OpenRTK™ application with Microsoft Visual® C++ in just a few minutes.
1. Checklist
2. Create your first application
Step 1: Create an empty project.
Step 2: Add necessary RTK files to the project.
Step 3: Add resources.
Step 4: Modify class definition.
Step 5: Add RTK variables.
Step 6: Add engine initialization.
Step 7: Add image loading.
Step 8: Add locate.
Step 9: Add recognition.
Step 10: Add export.
Step 11: Add engine termination.
3. Enjoy OpenRTK™
|
| 1. CheckList
To write your first OpenRTK™ application, you will need:
-
OpenRTK™ 7.0. It includes OpenRTK™.H, OpenRTK™.LIB, OpenRTK™.DLL, OpenRTK™.DB and GENERAL.*. If you haven't bought OpenRTK™ yet and want to have a review, please contact our sales person directly. You may need to sign some pre-purchase agreements.
-
Microsoft Visual® C++ 6.0 or above. Basic VC programming skill is required. If you are not familiar with VC, please refer to corresponding VC documentation first, and then start this tutorial.
2. Creating your first application
Your first OpenRTK™ application FirstOpenRTK™ will simply recognize an image and export the recognition result. In the next few minutes, we will walk you through every step of the OCR procedure. You will be taught how to initialize OpenRTK™ engine, how to terminate OpenRTK™ engine, how to get page, how to locate page, how to recognize page and how to export processing result. You can download this demo program (not including OpenRTK™ files) to your computer and avoid a lot of typing.
Step 1: Create an empty project.
Start up your Visual® C++ 6.0, create a new MFC AppWizard (EXE) project, and name it FirstOpenRTK™. Select "Dialog based" for the type of application. And then press "Finish" button to finish creating this project.
Step 2: Add necessary OpenRTK™ files to the project.
Copy OpenRTK™.DLL, OpenRTK™.LIB and OpenRTK™.H to the directory of the project. And add OpenRTK™.LIB and OpenRTK™.H to "Source Files" in VC.
Step 3: Add resources.
Open "Resources" of FirstOpenRTK™, and select "Dialog: IDD_FIRSTOpenRTK™_DIALOG". Add some controls according to Table 1. The four Big Buttons represent the four main steps to OCR an image. The progress bar is used to display the progress of processing. The Status is used to display processing messages. You can arrange these controls as below, or you can layout them as you will.
|
Table 1. Added Resources
| Control Type
| Object ID
| Caption |
| Button |
IDC_GETPAGE |
Get Page |
| Button |
IDC_LOCATE |
Locate |
| Button |
IDC_RECOGNIZE |
Recognize |
| Button |
IDC_EXPORT |
Export |
| Progress |
IDC_PROGRESS |
|
| Static Text |
IDC_STATUS |
|
|
 |
|
Step 4: Modify class definition.
Open ClassWizard, select Class name: CFirstOpenRTK™Dlg. Add member variables and member functions according to Table 2 and Table3.
|
Table 2. Member Variables
| Object ID
| Member
Variable
Type
| Member
Variable Member |
| IDC_STATUS |
Value:
CString |
m_status |
| IDC_PROGRESS |
Control:
CprogressCtrl |
m_Progress |
|
Table 3. Member Functions
| Object ID
| Messages |
| CFirstOpenRTK™Dlg |
WM_DESTROY |
| IDC_GETPAGE |
BN_CLICKED |
| IDC_LOCATE |
BN_CLICKED |
| IDC_RECOGNIZE |
BN_CLICKED |
| IDC_EXPORT |
BN_CLICKED |
|
|
Step 5: Add OpenRTK™ variables.
Open FirstOpenRTK™Dlg.H, add,
And in the declaration of class CFirstOpenRTK™Dlg, add
public:
PRTKCLIENT pRTKClient;
PRTKPAGE pRTKPage; |
Step 6: Add engine initialization in FirstRTKDlg.CPP.
CFirstOpenRTK™Dlg::OnInitDialog()
BOOL CFirstRTKDlg::OnInitDialog()
{
...
// TODO: Add extra initialization here
GetDlgItem(IDC_GETPAGE)->EnableWindow(TRUE);
GetDlgItem(IDC_LOCATE)->EnableWindow(FALSE);
GetDlgItem(IDC_RECOGNIZE)->EnableWindow(FALSE);
GetDlgItem(IDC_EXPORT)->EnableWindow(FALSE);
// Initialize RTK engine
USHORT status = RTKInit("Path of RTK","Path of temp file","RTK customer ID");
if(status != NOERROR)
m_Status = "RTKInit error!";
else
m_Status = "RTKInit successfully.";
UpdateData(FALSE);
...
} |
Notes:
-
Path of RTK: The path containing OpenRTK™.DB and GENERAL.*.
-
Path of temp file: The path containing temp file generated by OpenRTK™, usually same as "Path of OpenRTK™".
-
Customer ID: Your OpenRTK™ customer ID.
Step 7: Add image loading in FristOpenRTK™Dlg.CPP.
CFirstOpenRTK™Dlg::OnGetpage()
void CFirstRTKDlg::OnGetpage()
{
// TODO: Add your control notification handler code here
RTKClientCreate(&pRTKClient);
RTKClientPageInsert(pRTKClient, 0);
RTKClientPageNLock(pRTKClient, 0, &pRTKPage);
PRTKIMAGE pImage = RTKPageImageGet(pRTKPage);
CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrFilter = "TIFF Image Format (*.TIF)\0*.tif\0\0";
if(dlg.DoModal() == IDOK)
{
RTKImageFileRead(pImage, dlg.GetPathName().GetBuffer(255), (USHORT)(RTKIMAGE_TYPETIFF | RTKIMAGE_PORTRAIT), 0);
m_Status = "GetPage Finish!";
UpdateData(FALSE);
GetDlgItem(IDC_GETPAGE)->EnableWindow(FALSE);
GetDlgItem(IDC_LOCATE)->EnableWindow(TRUE);
}
} |
Step 8: Add locate in FirstRTKDlg.CPP.
CFirstRTKDlg::OnLocate()
void CFirstRTKDlg::OnLocate()
{
// TODO: Add your control notification handler code here
USHORT status, usProgress;
m_Progress.SetPos(0);
do
{
status = RTKPageLocate(pRTKPage, pRTKClient);
usProgress = RTKPageProgressGet(pRTKPage);
m_Progress.SetPos(usProgress);
} while (status == NOERROR);
m_Progress.SetPos(0);
m_Status = "Locate Finish!";
UpdateData(FALSE);
GetDlgItem(IDC_LOCATE)->EnableWindow(FALSE);
GetDlgItem(IDC_RECOGNIZE)->EnableWindow(TRUE);
} |
Step 9: Add recognition in FirstRTKDlg.CPP.
CFirstRTKDlg::OnRecognize ()
void CFirstRTKDlg::OnRecognize()
{
// TODO: Add your control notification handler code here
USHORT status, usProgress;
m_Progress.SetPos(0);
do
{
status = RTKPageRecognize(pRTKPage, pRTKClient);
usProgress = RTKPageProgressGet(pRTKPage);
m_Progress.SetPos(usProgress);
} while (status == NOERROR);
m_Progress.SetPos(0);
m_Status = "Recognize Finish!";
UpdateData(FALSE);
GetDlgItem(IDC_RECOGNIZE)->EnableWindow(FALSE);
GetDlgItem(IDC_EXPORT)->EnableWindow(TRUE);
} |
Step 10: Add export in FirstRTKDlg.CPP.
CFirstRTKDlg::OnExport()
void CFirstRTKDlg::OnExport()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(FALSE);
dlg.m_ofn.lpstrFilter = "Rich Text Format (*.RTF)\0*.rtf\0\0";
dlg.m_ofn.lpstrDefExt = "rtf";
if(dlg.DoModal() == IDOK)
{
RTKClientExport(pRTKClient, RTKEXPORT_ASCII,
dlg.GetPathName().GetBuffer(255));
RTKClientDestroy(pRTKClient);
m_Status = "Export Finish!";
UpdateData(FALSE);
GetDlgItem(IDC_EXPORT)->EnableWindow(FALSE);
GetDlgItem(IDC_GETPAGE)->EnableWindow(TRUE);
}
} |
Step 11: Add engine ternmination in FirstRTKDlg.CPP.
CFirstRTKDlg::OnDestory()
void CFirstRTKDlg::OnDestroy()
{
...
// TODO: Add your message handler code here
RTKTerm();
} |
3. Enjoy OpenRTK™
Your first simple OpenRTK™ application is almost done. Now take a little time to compile/link the project. After you build the project successfully, you can run it and enjoy the power of award-winning OCR technology.
Congratulations!
You've just finished your first OpenRTK™ application. Isn't it as easy as 123?
We hope that you enjoy this tutorial and begin to build your own application to explore other advanced features of OpenRTK™. |
|