www.pudn.com > PlateDSP.rar > main.cpp


//--------------------------------------------------------------------------- 
 
#include  
#pragma hdrstop 
 
#include "main.h" 
#include  
 
//--------------------------------------------------------------------------- 
#pragma package(smart_init) 
#pragma link "PlateDSP_OCX" 
#pragma resource "*.dfm" 
TForm1 *Form1; 
//--------------------------------------------------------------------------- 
__fastcall TForm1::TForm1(TComponent* Owner) 
    : TForm(Owner) 
{ 
    bDisableShow = false; 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::FormShow(TObject *Sender) 
{ 
    //clear msg 
    LabelPlateNumber->Caption = ""; 
    LabelPlateType->Caption = ""; 
    LabelPlateColor->Caption = ""; 
    LabelPlatePercent->Caption = ""; 
    //connect #1 video capture card 
    PlateDSPX1->VideoConnect(0); 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::PlateDSPX1Recoged(TObject *Sender, long PlateNum) 
{ 
    try 
    { 
        //save and display captured bmp 
        AnsiString TmpFile; 
        TmpFile = ExtractFilePath(Application->ExeName) + "CaptureTmp1.bmp"; 
        PlateDSPX1->SaveCapturePicture( WideString(TmpFile) ); 
        ImageCar->Picture->LoadFromFile( TmpFile ); 
        //check recog result 
        if( PlateNum > 0 ) 
        { 
            //get recognition result 
            LabelPlateNumber->Caption = PlateDSPX1->GetPlateNumber(0); 
            LabelPlateType->Caption = "种类:" + AnsiString(PlateDSPX1->GetPlateClassName(0)); 
            LabelPlateColor->Caption = "颜色:" + AnsiString(PlateDSPX1->GetPlateColor(0)); 
            int i = -1; 
            int Per = PlateDSPX1->GetPlateReliability(0,i); 
            AnsiString PerStr = "置信度:" + AnsiString(Per) + " ("; 
            while ( 1 ) 
            { 
                Per = PlateDSPX1->GetPlateReliability(0, ++i); 
                if( Per >= 0 ) 
                { 
                    PerStr = PerStr + " " + AnsiString(Per); 
                } 
                else 
                { 
                    break; 
                } 
            }; 
            LabelPlatePercent->Caption = PerStr + " )"; 
            TmpFile = ExtractFilePath(Application->ExeName) + "PlateTmp1.bmp"; 
            PlateDSPX1->SavePlatePicture( 0, WideString(TmpFile) ); 
            PlateDSPX1->GetPlateRect(0,&PlateRect.left,&PlateRect.top,&PlateRect.right,&PlateRect.bottom); 
            ImagePlate->Picture->LoadFromFile( TmpFile ); 
            ImagePlate->Visible = true; 
        } 
        else 
        { 
            LabelPlateNumber->Caption = ""; 
            LabelPlateType->Caption = ""; 
            LabelPlateColor->Caption = ""; 
            LabelPlatePercent->Caption = ""; 
            ImagePlate->Visible = false; 
        } 
    } 
    catch(...) 
    { 
    } 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::NBMPFileClick(TObject *Sender) 
{ 
    try { 
        std::auto_ptr OpenDialog(new TOpenDialog(this)); 
        OpenDialog->InitialDir = ExtractFilePath(Application->ExeName); 
        OpenDialog->Filter = "All (*.jpg;*.jpeg;*.bmp)|*.jpg;*.jpeg;*.bmp|" 
                             "JPEG Image File (*.jpg;*jpeg)|*.jpg;*jpeg|" 
                             "Bitmaps (*.bmp)|*.bmp"; 
        OpenDialog->Options << ofReadOnly << ofPathMustExist << ofFileMustExist; 
        if( OpenDialog->Execute() ) 
        { 
            PlateDSPX1->FileRecog( WideString(OpenDialog->FileName) ); 
        } 
    } 
    catch (...) 
    { 
    } 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::NMPGFileClick(TObject *Sender) 
{ 
    try { 
        std::auto_ptr OpenDialog(new TOpenDialog(this)); 
        OpenDialog->InitialDir = ExtractFilePath(Application->ExeName); 
        OpenDialog->Filter = "All (*.avi;*.mpg;*.mpeg;*.wmv)|*.avi;*.mpg;*.mpeg;*.wmv|" 
                             "Video for windows file (*.avi)|*.avi|" 
                             "MPEG file (*.mpg;*.mpeg)|*.mpg;*.mpeg|" 
                             "Windows media file (*.wmv)|*.wmv"; 
        OpenDialog->Options << ofReadOnly << ofPathMustExist << ofFileMustExist; 
        if( OpenDialog->Execute() ) 
        { 
            PlateDSPX1->FileRecog( WideString(OpenDialog->FileName) ); 
        } 
    } 
    catch (...) 
    { 
    } 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::NRecogSetClick(TObject *Sender) 
{ 
    PlateDSPX1->RecogDlg(); 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::NControlSetClick(TObject *Sender) 
{ 
    PlateDSPX1->ControlDlg(); 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::NVideoRestartClick(TObject *Sender) 
{ 
    PlateDSPX1->VideoConnect(0); 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::NAboutClick(TObject *Sender) 
{ 
    PlateDSPX1->AboutDlg(); 
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TForm1::NCloseClick(TObject *Sender) 
{ 
    Close();     
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TForm1::ImagePlateMouseMove(TObject *Sender, 
      TShiftState Shift, int X, int Y) 
{ 
    ImagePlate->Hint = String(PlateRect.right-PlateRect.left+1) + "x" + 
                       String(PlateRect.bottom-PlateRect.top+1); 
} 
//---------------------------------------------------------------------------