/*
/////gtamilocr.cpp////////, main gui module with all preprcoessing functions
GNU Tamil OCR
Copyright (C) 2004,2005 Visweswara R, visweswara@users.sourceforge.net
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
This program is just a GUI outline version, does not include recognition functions
contributions: GUI enhancement,splash screen ,noise removal functions by Janagaraj V,janagaraj@users.sourceforge.net
*/
#include "gtamilocr.h"
///debug function
MyFrame* logwin;
wxLogWindow *lg;
wxFFile filr;
wxTextCtrl* logtext;
wxLog *logtarget;
////debugfunction
BEGIN_EVENT_TABLE(MyFeatureDialog,wxDialog)
END_EVENT_TABLE()
MyFeatureDialog::MyFeatureDialog( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &position, const wxSize& size, long style ) :
wxDialog( parent, id, title, position, size, style )
{
// dialog function Features Select for MyFeatureDialog
Features_Select( this, TRUE );
}
//------------------------------------------------------------------------------
// MyTamilFrame
//------------------------------------------------------------------------------
// event table for MyTamilFrame
BEGIN_EVENT_TABLE(MyTamilFrame,wxFrame)
EVT_MENU(ID_ABOUT, MyTamilFrame::OnAbout)
EVT_MENU(ID_QUIT, MyTamilFrame::OnQuit)
EVT_CLOSE(MyTamilFrame::OnCloseWindow)
EVT_SIZE(MyTamilFrame::OnSize)
EVT_MENU( ID_FEATURE, MyTamilFrame::OnFeature )
EVT_MENU( ID_ABOUT, MyTamilFrame::OnAbout )
EVT_MENU( ID_OPEN, MyTamilFrame::OnOpen )
EVT_MENU( ID_SAVE_IMAGE, MyTamilFrame::OnSave )
EVT_MENU( ID_SAVEIMAGEAS, MyTamilFrame::OnSaveimageas )
EVT_MENU( ID_SAVETEXTAS, MyTamilFrame::OnSavetextas )
EVT_MENU( ID_READ, MyTamilFrame::OnRead )
EVT_MENU( ID_BATCH, MyTamilFrame::OnBatch )
EVT_MENU( ID_OPTIONS, MyTamilFrame::OnOptions )
EVT_MENU( ID_CLEAR, MyTamilFrame::OnClear )
EVT_MENU( ID_REVIMAGE, MyTamilFrame::OnRevimage )
EVT_MENU( ID_90, MyTamilFrame::OnRotate90 )
EVT_MENU( ID_180, MyTamilFrame::OnRotate180 )
EVT_MENU( ID_270, MyTamilFrame::OnRotate270 )
EVT_MENU( ID_SKEW, MyTamilFrame::OnSkew )
EVT_MENU( ID_FEATURE, MyTamilFrame::OnFeature )
EVT_MENU( ID_ZOOMIN, MyTamilFrame::OnZoomin )
EVT_MENU( ID_ZOOMOUT, MyTamilFrame::OnZoomout )
EVT_MENU( ID_FIT, MyTamilFrame::OnFit )
EVT_MENU( ID_FONTS, MyTamilFrame::OnFont )
EVT_MENU( ID_SEGMENT, MyTamilFrame::OnSegment )
EVT_MENU( ID_USING, MyTamilFrame::OnUsinghelp )
EVT_TOOL( ID_TOOLOPEN, MyTamilFrame::OnOpen )
EVT_TOOL( ID_TOOLSAVE, MyTamilFrame::OnSave )
EVT_TOOL( ID_TOOLSAVEAS, MyTamilFrame::OnSaveimageas )
EVT_TOOL( ID_TOOLZOOMIN, MyTamilFrame::OnZoomin )
EVT_TOOL( ID_TOOLZOOMOUT, MyTamilFrame::OnZoomout )
EVT_TOOL( ID_TOOLSKEW, MyTamilFrame::OnSkew )
EVT_TOOL( ID_TOOLREAD, MyTamilFrame::OnRead )
END_EVENT_TABLE()
MyTamilFrame::MyTamilFrame( wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &position, const wxSize& size, long style ) :
wxFrame( parent, id, title, position, size, style )
{
CreateMyMenuBar();
CreateMyToolBar();
CreateStatusBar(1);
SetStatusText( wxT("Welcome To GNU Tamil OCR") );
imagebox=new MyImageBox(this,-1,"Imagebox",wxDefaultPosition, wxSize(500,500), wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER | wxCAPTION );
imagebox->Show();
tamiltextctrl=new wxTextCtrl(this,-1," ",wxDefaultPosition,wxDefaultSize, wxTE_MULTILINE |wxTE_LEFT , wxDefaultValidator, wxTextCtrlNameStr);
tamiltextctrl->SetFont(wxFont(16,wxNORMAL, wxNORMAL, wxBOLD, 0, "tscarial"));
////debug//////
logwin = new MyFrame(this, -1, "Log Window",wxPoint(100,100),wxSize(500,300));
logwin->Show();
logtarget->SetActiveTarget( new wxLogTextCtrl(logwin->logtext) );
///end debug/////
}
void MyTamilFrame::CreateMyMenuBar()
{
SetMenuBar( MyMenuBarFunc() );
}
void MyTamilFrame::CreateMyToolBar()
{
wxToolBar *tb = CreateToolBar(/* wxTB_VERTICAL*/wxTB_HORIZONTAL|wxTB_TEXT|wxTB_3DBUTTONS );
MyToolBarFunc( tb );
}
void MyTamilFrame::OnUsinghelp( wxCommandEvent &event )
{
}
/** function to call segment and train dialog */
void MyTamilFrame::OnSegment( wxCommandEvent &event )
{
train=new MyTrain(this,-1,"Segement");
train->Show();
//wxMessageBox("Segment");
}
void MyTamilFrame::OnFont( wxCommandEvent &event )
{
wxFontData data;
wxFontDialog fond(this,data);
if(fond.ShowModal()==wxID_OK)
{
wxFontData fdata = fond.GetFontData();
wxFont font = fdata.GetChosenFont();
wxColour colour = fdata.GetColour();
tamiltextctrl->SetFont(font);
}
}
void MyTamilFrame::OnFit( wxCommandEvent &event )
{
zoomlevel = 1;
freshredraw();
imagebox->Refresh();
}
/** function to zoom out */
void MyTamilFrame::OnZoomout( wxCommandEvent &event )
{
switch(zoomlevel)
{
case 3:
zoomlevel=3 ;
break;
case 0:
zoomlevel=1 ;
break;
case 1:
zoomlevel=2 ;
break;
case 2:
zoomlevel=3 ;
break;
}
freshredraw();
imagebox->Refresh();
}
/** function to zoom in */
void MyTamilFrame::OnZoomin( wxCommandEvent &event )
{
switch(zoomlevel)
{
case 3:
zoomlevel=2 ;
break;
case 2:
zoomlevel=1 ;
break;
case 1:
zoomlevel=0 ;
break;
case 0:
zoomlevel=0;
break;
}
freshredraw();
imagebox->Refresh();
}
void MyTamilFrame::OnSkew( wxCommandEvent &event )
{
CImage Img,Imgtemp;
CCoordinateTransform ctran;
double skew1,skew2,skewangle;
Img.Load("temp1.bmp");
Imgtemp.CopyConvert(1,Img);
wxBeginBusyCursor(wxHOURGLASS_CURSOR);
skew1=findskew(Imgtemp);
ctran.ScaleAndRotateAuto(Imgtemp,Imgtemp,1,1,skew1,1);
skew2=findskew(Imgtemp);
skewangle=(skew1+skew2);
ctran.ScaleAndRotateAuto(Img,Imgtemp,1,1,skewangle,1);
Imgtemp.Save("temp1.bmp");
wxEndBusyCursor();
wxLogMessage("%f",skew1*180/3.14);
freshredraw();
imagebox->Refresh(true, NULL);
wxMessageBox("Skew Corrected");
}
/** function to rotate image 270 degree */
void MyTamilFrame::OnRotate270( wxCommandEvent &event )
{
CImage Img;
Img.Load("temp1.bmp");
Img.Rotate90(3);
Img.Save("temp1.bmp");
freshredraw();
imagebox->Refresh();
}
/** function to rotate image 180 degree */
void MyTamilFrame::OnRotate180( wxCommandEvent &event )
{
CImage Img;
Img.Load("temp1.bmp");
Img.Rotate90(2);
Img.Save("temp1.bmp");
freshredraw();
imagebox->Refresh();
}
/** function to rotate image 90 degree */
void MyTamilFrame::OnRotate90( wxCommandEvent &event )
{
CImage Img;
Img.Load("temp1.bmp");
Img.Rotate90(1);
Img.Save("temp1.bmp");
freshredraw();
imagebox->Refresh();
}
/** function to invert the colur of image */
void MyTamilFrame::OnRevimage( wxCommandEvent &event )
{
CImage Img;
Img.Load("temp1.bmp");
Img.Invert();
Img.Save("temp1.bmp");
freshredraw();
imagebox->Refresh();
}
/** function to clear "Salt and Pepper Noise" */
void MyTamilFrame::OnClear( wxCommandEvent &event )
{
CImage Img,Imgdest;
int i,j;
int x,y;
wxBeginBusyCur