怎样进行图象识别?(过江项羽)

luhongjun 2002-07-23 02:53:58
以前灌水,有网友做了一个《水军提督》软件,里面把图象变成字符图象。这是怎样实现的?做过的网友希望不吝指教,学生这里有礼了,没作过的帮想想办法。没有时间也没做过的,帮住推推帖子,贴主再此表示感谢。

...全文
109 31 打赏 收藏 转发到动态 举报
写回复
用AI写文章
31 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2002-07-24
  • 打赏
  • 举报
回复
关注吧
lining_cumt985 2002-07-24
  • 打赏
  • 举报
回复
做个标记。
abomb 2002-07-24
  • 打赏
  • 举报
回复
UP、UP,高手出招,就是不一样哇
luhongjun 2002-07-24
  • 打赏
  • 举报
回复
问题这么快就解决了,谢谢朋友们的帮助。
尤其感谢ALNG(?) 兄的鼎立帮忙。
Canvas 2002-07-24
  • 打赏
  • 举报
回复
热闹
wangxd 2002-07-24
  • 打赏
  • 举报
回复
够了
勉励前行 2002-07-24
  • 打赏
  • 举报
回复
向這麼多位學習,學習。
孩皮妞野 2002-07-24
  • 打赏
  • 举报
回复
测试通过。

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Memo1->Font->Name="Fixedsys";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(OpenDialog1->Execute()){
Graphics::TBitmap * bmp = new Graphics::TBitmap;
try{
bmp->LoadFromFile(OpenDialog1->FileName);
ConvertToText(bmp,Memo1->Lines);
}catch(...){
ShowMessage("Error proccessing the file!");
}
delete bmp;
}

}
//---------------------------------------------------------------------------
void TForm1::ConvertToText( const Graphics::TBitmap *const bmp, TStrings * sl)
{
static char *map="#M@HX$%+/;:=-,. ";

sl->Clear();
Graphics::TBitmap * tmp = new Graphics::TBitmap;
tmp->Assign(const_cast<Graphics::TBitmap *>(bmp));
tmp->PixelFormat = pf24bit;
for (int y = 0; y < tmp->Height; y++)
{
String s;
BYTE *ptr =(BYTE *) tmp->ScanLine[y];
for (int x = 0; x < tmp->Width*3; x+=3){
long Gray=(30*ptr[x+2]+59*ptr[x+1]
+11*ptr[x])/1594;
s += map[Gray];
}
sl->Add(s);
}
delete tmp;


}
//---------------------------------------------------------------------------
wjzhuang 2002-07-24
  • 打赏
  • 举报
回复
mark
wjzhuang 2002-07-24
  • 打赏
  • 举报
回复
mark
孩皮妞野 2002-07-24
  • 打赏
  • 举报
回复
这是从Adayuer(狗日的爱情) 推荐的网址找到的核心代码,
BOOL CJDib::ConvertToText(CString strBMPName)
{
//字符调色盘
BYTE CharPalette[16];
CharPalette[0] = '#';
CharPalette[1] = 'M';
CharPalette[2] = '@';
CharPalette[3] = 'H';
CharPalette[4] = 'X';
CharPalette[5] = '$';
CharPalette[6] = '%';
CharPalette[7] = '+';
CharPalette[8] = '/';
CharPalette[9] = ';';
CharPalette[10] = ':';
CharPalette[11] = '=';
CharPalette[12] = '-';
CharPalette[13] = ',';
CharPalette[14] = '.';
CharPalette[15] = ' ';

CString strTxtName = strBMPName;
//计算文本文件名
strTxtName = strTxtName.Left(strTxtName.Find('.'));
strTxtName += ".txt";

CStdioFile TxtFile;
//创建文本文件
if (!TxtFile.Open(strTxtName, CFile::modeCreate | CFile::modeWrite | CFile::typeText))
{
CString strErrorMessage;
strErrorMessage = "创建文本文件:" + strTxtName + "失败 !";
AfxMessageBox(strErrorMessage);
return FALSE;
}

//读取 BMP文件数据
if (!Read(strBMPName))
{
return FALSE;
}

TxtFile.WriteString("Generated by 老魏!\n");

//取得 BMP数据指针
BYTE *pData = (BYTE *)m_pData;
BYTE *pLine = pData;

for (int i = m_lpBMInfoHeader->biHeight - 1; i >= 0; i--)
{
//计算每行的数据指针
pLine = pData + i * m_nBytesPerLine;
CString strLineText;
for (int j = 0; j < m_lpBMInfoHeader->biWidth; j++)
{
int nRed, nGreen, nBlue, nValue;

//计算当前象素的 RGB三分量的值
switch (m_lpBMInfoHeader->biBitCount)
{
case 24:
nRed = *pLine++;
nGreen = *pLine++;
nBlue = *pLine++;
break;

case 8:
nRed = m_lpLogPalette->palPalEntry[*pLine].peRed;
nGreen = m_lpLogPalette->palPalEntry[*pLine].peGreen;
nBlue = m_lpLogPalette->palPalEntry[*pLine].peBlue;
pLine++;
break;

default:
AfxMessageBox("抱歉, 当前版本仅支持 8bit和24bit文件 !");
return FALSE;
}

//计算灰度值
nValue = (nRed * 30 + nGreen * 59 + nBlue * 11) / 100;

//转换到文本
strLineText += CharPalette[nValue / 16];
}

//写入文本文件
TxtFile.WriteString(strLineText);
TxtFile.WriteString("\n");
}

TxtFile.Close();

return TRUE;
}

用C++Builder来实现应该更容易,而且支持的位图格式可以更多。

上面的算法主旨就是把位图中样点的灰度值映射到0-15中的一个值,而每个值又对应一个特定的字符。

我相信这个实现不是唯一的,可以有其他甚至更好的方案。
ChineseBcb 2002-07-24
  • 打赏
  • 举报
回复
Raptor(猛禽) :说的方法不错。这样应该很好实现。
三杯倒 2002-07-24
  • 打赏
  • 举报
回复
关注吧
  • 打赏
  • 举报
回复
多年未见啊!!
以前硬盘没坏的时候,倒是有一个小日本的程序源码。
不过现在没有了:)
xrbeck 2002-07-23
  • 打赏
  • 举报
回复
项老大的问题只能来表示关注了。。
781014 2002-07-23
  • 打赏
  • 举报
回复
qdxby 2002-07-23
  • 打赏
  • 举报
回复
UP
猛禽 2002-07-23
  • 打赏
  • 举报
回复
项兄对灌水也这么有兴趣?^_^
我想到的一个办法是:先把图像转为灰度图片0.59G+0.30R+0.11B(好象是这样^_^),再生成一个字符灰度表,记录一些字符的灰度(以黑色将这些字符显示在一个固定大小的白色方块里,统计其中黑色所占的比例),然后将图片中的点按其灰度用相应字符代替即可。
gudufeixiang 2002-07-23
  • 打赏
  • 举报
回复
如果是转化成ascll码的图象好象在有个很小的软件可以解决,华军软件上可以找到
mygodness 2002-07-23
  • 打赏
  • 举报
回复
什么意思?是像扫描仪扫描出来的文字进行识别?像手写板一样吗?
加载更多回复(11)

13,822

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧