📄 analyze_map.cpp
字号:
// Analyze_map.cpp: implementation of the CAnalyze_map class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "test.h"
#include "Analyze_map.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CAnalyze_map::CAnalyze_map()
{
}
CAnalyze_map::~CAnalyze_map()
{
}
CAnalyze_map::CAnalyze_map(LONG widch, LONG height)
{
Width = widch;
Height = height;
}
void CAnalyze_map::analyse_chara(intarr& ints, bitarr& inputs)
{ int res[13]={0,0,0,0,0,0,0,0,0,0,0,0,0};
int maple[144][144];
int i,j,ii,i_count;
BYTE data;
LONG count;
BOOL find;
count=inputs.GetSize();
ii=0;
i_count=0;
for (i=0;i<144;i++)
{
for (j=0;j<144;j++) {
maple[i][j]=1;
}
}
j=0;
while (ii<count-2)
{
data=inputs.GetAt(ii);
for (i=0;i<8;i++,i_count++)
{
maple[j][i_count] = (int)data/128;
data=data<<1;
}
if (i_count + 1>= Width)
{
i_count = 0;
j++;
}
ii++;
}
find=TRUE;
//读入数据完毕,开始查找图像字符开始的坐标和长度,宽度。
for (j=0;j<144&&find;j++)
{
for (i=0;i<144;i++)
{
if (maple[j][i]==0)
{
start_y = j;
find = FALSE;
break;
}
}
}
//----------------------------------------------------------
find = TRUE;
for (j=0;j<144&&find;j++)
{
for (i=0;i<144;i++)
{
if (maple[i][j]==0)
{
start_x = j;
find = FALSE;
break;
}
}
}
//------------------------------------------------------------
find = TRUE;
for (j=143;j>0&&find;j--)
{
for (i=0;i<144;i++)
{
if (maple[j][i]==0)
{
Height_in = j - start_y;
find = FALSE;
break;
}
}
}
//-------------------------------------------------------------
find = TRUE;
for (j=143;j>0&&find;j--)
{
for (i=0;i<144;i++)
{
if (maple[i][j]==0)
{
Width_in = j - start_x;
find = FALSE;
break;
}
}
}
//-------------------------------------------------------------
int num;
for (ii=0;ii<5;ii++)
{
num = 0;
j = (int)(start_y+ii*(Height_in)/4.0);
for(i=start_x;i<=Width_in+start_x;i++)
{
if (maple[j][i]==0) num++;
while (maple[j][i]==0)
{
i++;
}
}
res[ii] = num;
}
//=============================================
for (ii=0;ii<5;ii++)
{
num=0;
j = (int)(start_x+ii*(Width_in)/4.0);
for(i=start_y;i<=Height_in+start_y;i++)
{
if (maple[i][j]==0) num++;
while (maple[i][j]==0)
{
i++;
}
}
res[ii+5] = num;
}
//========================================================
int center_x,center_y;
if (Height_in>=Width_in)
{
center_y = start_x;
center_x = start_y+(Height_in-Width_in)/2.0;
}
else
{
center_x = start_y;
center_y = start_x+(Width_in-Height_in)/2.0;
}
num=0;
for (;center_x<=start_y+Height_in&¢er_y<=start_x+Width_in;center_x++,center_y++)
{
if (maple[center_x][center_y]==0||(maple[center_x+1][center_y]==0&&maple[center_x][center_y+1]==0))
num++;
while (maple[center_x][center_y]==0)
{
center_x++;
center_y++;
}
}
res[10] = num;
//---------------------------------------------------------------
if (Height_in>Width_in)
{
center_y = start_x;
}
else
{
center_y = Height_in-(center_y - start_x)+start_x;
}
num=0;
for (;center_y<=start_x+Width_in&¢er_x>=start_y;center_x--,center_y++)
{
if (maple[center_x][center_y]==0||(maple[center_x-1][center_y]==0&&maple[center_x][center_y+1]==0))
num++;
while (maple[center_x][center_y]==0)
{
center_x--;
center_y++;
}
}
res[11] = num;
//=============================================================
//找出端点个数;
num=0;
CString bb;
int countodd;
for (j=start_y;j<start_y+Height_in+1;j++)
{
for (i=start_x;i<start_x+Width_in+1;i++)
{
countodd=0;
if(maple[j][i]==0)
{
if (maple[j-1][i-1]==0)
countodd++;
if (maple[j-1][i]==0)
countodd++;
if (maple[j-1][i+1]==0)
countodd++;
if (maple[j+1][i-1]==0)
countodd++;
if (maple[j+1][i]==0)
countodd++;
if (maple[j+1][i+1]==0)
countodd++;
if (maple[j][i-1]==0)
countodd++;
if (maple[j][i+1]==0)
countodd++;
if (countodd==1)
num++;
}
}
}
res[12] = num;
//display
CString ss;/*aa,
for (i=0;i<13;i++)
{
aa.Format("%d",res[i]);
ss+=aa;
}
AfxMessageBox(ss);
*/
i=res[1];
res[1] = res[3];
res[3] = i;
ints.RemoveAll();
for (i=0;i<13;i++)
ints.Add(res[i]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -