Смекни!
smekni.com

Программа распознавания символов (стр. 2 из 2)

if (B < 255)

{

ToLine = (Byte*)ToImage->ScanLine[cY];

ToLine[cX] = 0;

Vertex.X = cX;

Vertex.Y = cY;

if (Distance(Vertex, ShapeVector[ShapeVector.size() - 1]) >= Treshold)

ShapeVector.push_back(Vertex);

Direct = North;

cY--;

Line = (Byte*)FromImage->ScanLine[cY];

}

// Иначе поворачиваем "направо"

else

{

Direct = South;

cY++;

Line = (Byte*)FromImage->ScanLine[cY];

}

}

break;

// Юг

case South:

{

B = Line[cX];

// Если элемент "черный", поворачиваем снова "налево"

if (B < 255)

{

ToLine = (Byte*)ToImage->ScanLine[cY];

ToLine[cX] = 0;

Vertex.X = cX;

Vertex.Y = cY;

if (Distance(Vertex, ShapeVector[ShapeVector.size() - 1]) >= Treshold)

ShapeVector.push_back(Vertex);

Direct = East;

cX++;

}

// Иначе поворачиваем "направо"

else

{

Direct = West;

cX--;

}

}

break;

// Запад

case West:

{

B = Line[cX];

// Если элемент "черный", поворачиваем снова "налево"

if (B < 255)

{

ToLine = (Byte*)ToImage->ScanLine[cY];

ToLine[cX] = 0;

Vertex.X = cX;

Vertex.Y = cY;

if (Distance(Vertex, ShapeVector[ShapeVector.size() - 1]) >= Treshold)

ShapeVector.push_back(Vertex);

Direct = South;

cY++;

Line = (Byte*)FromImage->ScanLine[cY];

}

// Иначе поворачиваем "направо"

else

{

Direct = North;

cY--;

Line = (Byte*)FromImage->ScanLine[cY];

}

}

}

} while ((cX != X) || (cY != Y));

Vertex.X = X;

Vertex.Y = Y;

ShapeVector.push_back(Vertex);

ToImage->Canvas->Pen->Color = clRed;

ToImage->Canvas->MoveTo(ShapeVector[0].X, ShapeVector[0].Y);

for (UINT i = 1; i < ShapeVector.size(); i++)

{

ToImage->Canvas->LineTo(ShapeVector[i].X, ShapeVector[i].Y);

}

for (UINT i = 0; i < ShapeVector.size(); i++)

{

ShapeVector[i].X -= MinX;

ShapeVector[i].Y -= Y;

}

/*

if (Symb == 'Й')

{

Symb++;

}

if (Symb == 'а')

{

// Symb = 'A';

break;

}

if ((Symb != 'Ы') && (!SkipMode))

{

AnsiString FileName = ExtractFilePath(Application->ExeName) + "TPL&bsol;";

FileName += Symb;

ofstream OutFile(FileName.c_str());

for (UINT i = 0; i < ShapeVector.size(); i++)

{

OutFile << IntToStr(ShapeVector[i].X).c_str() << endl;

OutFile << IntToStr(ShapeVector[i].Y).c_str() << endl;

}

OutFile.close();

Symb++;

}

else

{

if (SkipMode)

{

SkipMode = false;

Symb++;

}

else if (Symb == 'Ы')

SkipMode = true;

}

*/

TTemplate* Template = FindTemplate(ShapeVector);

if (Template)

Result += Template->Symb;

}

//OSRForm->Show();

delete OSRForm;

Memo1->Text = Result;

}

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

TTemplate* FindTemplate(TShapeVector Vec)

{

TTemplate Template;

Template.Vec = Vec;

for (UINT i = 0; i < Templates.size(); i++)

{

if (Templates[i] == Template)

return &Templates[i];

}

return NULL;

}

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

Снапшоты программы.

Начало работы

Произведено распознавание.