基本信息
源码名称:ocr关于机器视觉的源码
源码大小:0.32M
文件格式:.rar
开发语言:C/C++
更新时间:2017-04-13
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
是很有帮助的源码
是很有帮助的源码
// testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "test.h"
#include "testDlg.h"
#include "OCRWencui.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, mlist);
//{{AFX_DATA_MAP(CTestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
//{{AFX_MSG_MAP(CTestDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDOK2, OnOk2)
ON_BN_CLICKED(IDtif2bmp, Ontif2bmp)
ON_BN_CLICKED(IDscan, Onscan)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon 1) / 2;
int y = (rect.Height() - cyIcon 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
TOCRResult* p;
CString s;
char *pTextResult;
if (!WOcrInit(iOcrTypeMultiLine | HZAll, //多行文字 所有字符
InfoAssociate | InfoRecognizeTable, //是否自动旋转 是否使用联想词库 图片中可能有多种不同大小的字体
0, //保留未用
-1, //字体最小值(像素)
-1, //字体最大值(像素)
5,
0, //保留未用
0 //保留未用
)) {
MessageBox("初始化WencuiOCRdll出错,请检查使用许可是否过期或与作者联系.");
return;
}
HBITMAP hbmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
"test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
if(hbmp){
if (WOcrStart(hbmp,
NULL,//BMP识别的矩形,NULL表示整个BMP
iGrayAuto, 0,
&p,//返回识别结果(每个文字及其坐标等信息)
&pTextResult,//返回识别结果(带空格的一行或多行文字)
"c:\\1.rtf")){//生成的RTF文件,为空表示不生成RTF文件
mlist.ResetContent();
for(int i=0;i<p->Count;i ){
//setlength(s,CountSuspect*2);
//move(ChineseSuspect[0],s[1],CountSuspect*2);
s.Format("%-4s 相似度:%3d%% Left:%-4d Right:%-4d Top:%-4d Bottom:%-4d 候选字:%s",
p->Result[i].Chinese, p->Result[i].Precision,
p->Result[i].Rect.left, p->Result[i].Rect.right, p->Result[i].Rect.top,p->Result[i].Rect.bottom,
p->Result[i].ChineseSuspect);
mlist.AddString(s);
}
MessageBox(pTextResult,"识别结果",0);
}
else ::MessageBox(0,"识别出错","提示",MB_OK);
}
else ::MessageBox(0,"找不到test.bmp","提示",MB_OK);
}
void CTestDlg::OnOk2()
{
TOCRResult* p;
CString s;
RECT rect;
char *pTextResult;
if (!WOcrInit(iOcrTypeMultiLine | HZAll, //多行文字 所有字符
InfoAssociate | InfoRecognizeTable, //是否自动旋转 是否使用联想词库 图片中可能有多种不同大小的字体
0, //保留未用
-1, //字体最小值(像素)
-1, //字体最大值(像素)
5,
0, //保留未用
0 //保留未用
)) {
MessageBox("初始化WencuiOCRdll出错,请检查使用许可是否过期或与作者联系.");
return;
}
HBITMAP hbmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(),
"test.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if(hbmp){
rect.left=156;
rect.right=507;
rect.top=40;
rect.bottom=100;
if (WOcrStart(hbmp,
&rect,//BMP识别的矩形,NULL表示整个BMP
iGrayAuto, 0,
&p,//返回识别结果(每个文字及其坐标等信息)
&pTextResult,//返回识别结果(带空格的一行或多行文字)
"c:\\1.rtf")){//生成的RTF文件,为空表示不生成RTF文件
mlist.ResetContent();
for(int i=0;i<p->Count;i ){
//setlength(s,CountSuspect*2);
//move(ChineseSuspect[0],s[1],CountSuspect*2);
s.Format("%-4s 相似度:%3d%% Left:%-4d Right:%-4d Top:%-4d Bottom:%-4d 候选字:%s",
p->Result[i].Chinese, p->Result[i].Precision,
p->Result[i].Rect.left, p->Result[i].Rect.right, p->Result[i].Rect.top,p->Result[i].Rect.bottom,
p->Result[i].ChineseSuspect);
mlist.AddString(s);
}
MessageBox(pTextResult,"识别结果",0);
}
else ::MessageBox(0,"识别出错","提示",MB_OK);
}
else ::MessageBox(0,"找不到test.bmp","提示",MB_OK);
}
void CTestDlg::Ontif2bmp()
{
// TODO: Add your control notification handler code here
if(WConvertToBmp("test.tif","bak.bmp",0))
::MessageBox(0,"test.tif成功转为bak.bmp","提示",MB_OK);
}
void CTestDlg::Onscan()
{
// TODO: Add your control notification handler code here
char Scaner[1024];
if (WScanerSelect(Scaner))
if (WScanParameter(Scaner,false,false, 0, 300, 0, 0, NULL))
if (WScanStartOnePage("bak.bmp"))
{
::MessageBox(0,"扫描完成,保存为bak.bmp","提示",MB_OK);
}
}