Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: easy way to recognize handwritten character





hi friend,

I can give you one of my version of code, it will give you actually
overview, it's quite lengthy, and you may find difficulty in
understanding it. But's It's my experience of trying it to solve it
for 2 years which has led to this conclusion.

You have to run this code in turboC. and

only problem you may get is in this


initgraph(&gd,&gm,"");

here  intigraph(&gd,&gm," <here you have set the turbo c's path"> ");

it can "C:\\turboc\\ continue where are your graphic files.

this code consist of all my testing of different type's how I tries to
solve.

If you want I can give you the orginal complet code once I return back
to my place( now I am out of station).

ok tyr it out

//this program is to produce character in the form of a graph then to
analyse the circuitry


#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <math.h>
#include <graphics.h>
#include <bmp.h>
#define MAX_VAL 3


int num=0;

struct Node
{
struct Node *D_R;
struct Node *D_L;
struct Node *U_R;
struct Node *U_L;

struct Node *D_R1;
struct Node *D_L1;
struct Node *U_R1;
struct Node *U_L1;

int x,y;
Node():D_R(NULL),D_L(NULL),U_R(NULL),U_L(NULL),D_R1(NULL),D_L1(NULL),U_R1(NULL),U_L1(NULL){}
};

struct copy_node
{
int d_r;
int d_l;
int u_r;
int u_l;
int d_r1;
int d_l1;
int u_r1;
int u_l1;

};

int xmin,ymin,xmax,ymax,xpos,ypos;


void main()
{
int gd=DETECT,gm;
void Drawing_Pencil(int,int);
float angle(int,int,int);
void movewithangle2(int,int,int,int,int,Node *);
void find_xpos_ypos(int &,int &);
void remove_red();
void write(char [],char []);
void traverse(Node * ,int,int &,char[]);
void copyback(int,int,int,int,int,int);
void copy(int,int,int,int,int,int);
int recognize_one(Node *);
int recognize_four(Node *);
int recognize_five(Node *);
int recognize_seven(Node *);
int recognize_six(Node *);
int recognize_three(Node *);
int recognize_A(Node *);
int recognize_E(Node *);
int recognize_L(Node *);
int recognize_T(Node *);
int recognize_J(Node *);

int find(char[],char[]);
void draw_graph(Node *,int,int &,char[],int,int);
void minimize_graph(Node *,Node *,int);
void minimize_graph_length(Node *,Node *);
void join_small_length_nodes(Node *,Node *,int);


initgraph(&gd,&gm,"");

int x,y;
union REGS reg;



rectangle(50,50,100,100);


reg.x.ax=1;
int86(0x33,&reg,&reg);


while(!kbhit())
{

reg.x.ax=5;
int86(0x33,&reg,&reg);

if(reg.x.bx==1)
{
Drawing_Pencil(reg.x.cx,reg.x.dx);
}
}
getch();


/*
loadbmp("z1.bmp",51,51);
loadbmp("z1.bmp",450,420);
//remove_red();
//copyback(51,51,99,99,120,120);
rectangle(50,50,100,100);
getch();
*/



copy(51,51,99,99,320,120);       //this to copy the picture at that
point to calculate the anlge of thepiclutre
getch();


find_xpos_ypos(xpos,ypos);
int xint,yint;

xint=xpos;
yint=ypos;


float ang;
int pos=0;

ang=angle(xpos,ypos,1);

if((ang>=70&&ang<=90)||(ang<=-70&&ang>=-90))
pos=2;
else if((ang>=0&&ang<=20)||(ang<=0&&ang>=-20))
pos=0;
else
pos=1;


cout<<pos;
getch();

Node *Head=new Node();
Head->x=xpos;
Head->y=ypos;

movewithangle2(xpos,ypos,xint,yint,pos,Head);

rectangle(320+50,50,320+100,100);


char  arr[30];
int position;

//traverse(Head,0,position,arr);
arr[position++]='\0';
arr[position]='\0';

gotoxy(23,23);
cout<<arr;

printf("Entreing the minimizing stage");
getch();
//just to mimimize the graph
        minimize_graph(Head,Head->D_L,1);
        minimize_graph(Head,Head->D_R,2);
        minimize_graph(Head,Head->U_R,3);
        minimize_graph(Head,Head->U_L,4);
        minimize_graph(Head,Head->D_L1,1);
        minimize_graph(Head,Head->D_R1,2);
        minimize_graph(Head,Head->U_R1,3);
        minimize_graph(Head,Head->U_L1,4);
//end of just to minimize the graph

/*
printf("Entreing the minimizing stage length");
getch();
//just to mimimize the graph
        minimize_graph_length(Head,Head->D_L);
        minimize_graph_length(Head,Head->D_R);
        minimize_graph_length(Head,Head->U_R);
        minimize_graph_length(Head,Head->U_L);
        minimize_graph_length(Head,Head->D_L1);
        minimize_graph_length(Head,Head->D_R1);
        minimize_graph_length(Head,Head->U_R1);
        minimize_graph_length(Head,Head->U_L1);

//end of just to minimize the graph
*/

printf("joinging small nodes ");
getch();

//is to remove the smallnodes

        if(Head->D_R!=NULL)
        join_small_length_nodes(Head,Head->D_R,1);
        if(Head->D_L!=NULL)
        join_small_length_nodes(Head,Head->D_L,2);
        if(Head->U_R!=NULL)
        join_small_length_nodes(Head,Head->U_R,3);
        if(Head->U_L!=NULL)
        join_small_length_nodes(Head,Head->U_L,4);
        if(Head->D_R1!=NULL)
        join_small_length_nodes(Head,Head->D_R1,5);
        if(Head->D_L1!=NULL)
        join_small_length_nodes(Head,Head->D_L1,6);
        if(Head->U_R1!=NULL)
        join_small_length_nodes(Head,Head->U_R1,7);
        if(Head->U_L1!=NULL)
        join_small_length_nodes(Head,Head->U_L1,8);




//end to remove small nodes

position=0;
draw_graph(Head,0,position,arr,400,400);
arr[position++]='\0';
arr[position]='\0';



if(recognize_one(Head)==1)
printf("It is one");

if(recognize_four(Head)==1)
printf("It is four");


if(recognize_seven(Head)==1)
printf("It is seven");

printf("Entering recognition for six");
getch();

if(recognize_six(Head)==1)
printf("It is six");


if(recognize_five(Head)==1)
printf("It is five");


if(recognize_three(Head)==1)
printf("It is three");

//printf("Entreing to recognize A");
//getch();

if(recognize_L(Head)==1)
printf("It is L");

if(recognize_A(Head)==1)
printf("It is A");

if(recognize_E(Head)==1)
printf("It is E");

if(recognize_T(Head)==1)
printf("It is T");

if(recognize_J(Head)==1)
printf("It is J");



/*
if(find(arr,"1.ann"))
{
cout<<"it is one";
}
else if(find(arr,"2.ann"))
{
cout<<"it is two";
}
else if(find(arr,"3.ann"))
{
cout<<"it is three";
}
else if(find(arr,"4.ann"))
{
cout<<"it is four";
}
else if(find(arr,"5.ann"))
{
cout<<"it is five";
}
else if(find(arr,"6.ann"))
{
cout<<"it is six";
}
else if(find(arr,"7.ann"))
{
cout<<"it is seven";
}
else if(find(arr,"8.ann"))
{
cout<<"it is six";
}
else
{
cout<<"it is not matched";
}
*/



/*
if(find(arr,"1"))
{
gotoxy(30,5);
cout<<"1 is found";
getch();
}
else
{
//this part is for training
write(arr,"1");
}
*/


getch();

}//end of main function

//function to join two nodes if the distance between the two nodes is
very small

void join_small_length_nodes(Node *Head,Node *temp,int which_dir)
{

float calculate_length(int,int,int,int);

        if(temp==NULL)
        return;

float length;

        length=calculate_length(Head->x,Head->y,temp->x,temp->y);

        if(length<5)
        {

                if(which_dir==1)
                Head->D_R=NULL;
                else if(which_dir==2)
                Head->D_L=NULL;
                else if(which_dir==3)
                Head->U_R=NULL;
                else if(which_dir==4)
                Head->U_L=NULL;
                else if(which_dir==5)
                Head->D_R1=NULL;
                else if(which_dir==6)
                Head->D_L1=NULL;
                else if(which_dir==7)
                Head->U_R1=NULL;
                else if(which_dir==8)
                Head->U_L1=NULL;


                if(temp->D_R!=NULL)
                {
                        if(Head->D_R!=NULL)
                        {
                        Head->D_R1=temp->D_R;
                        }
                        else
                        {
                        Head->D_R=temp->D_R;
                        }

                }

                if(temp->D_L!=NULL)
                {
                        if(Head->D_L!=NULL)
                        {
                        Head->D_L1=temp->D_L;
                        }
                        else
                        {
                        Head->D_L=temp->D_L;
                        }

                }

                if(temp->U_R!=NULL)
                {
                        if(Head->U_R!=NULL)
                        {
                        Head->U_R1=temp->U_R;
                        }
                        else
                        {
                        Head->U_R=temp->U_R;
                        }

                }

                if(temp->U_L!=NULL)
                {
                        if(Head->U_L!=NULL)
                        {
                        Head->U_L1=temp->U_L;
                        }
                        else
                        {
                        Head->U_L=temp->U_L;
                        }

                }
                if(temp->D_R1!=NULL)
                {
                        if(Head->D_R!=NULL)
                        {
                        Head->D_R1=temp->D_R1;
                        }
                        else
                        {
                        Head->D_R=temp->D_R1;
                        }

                }
                if(temp->D_L1!=NULL)
                {
                        if(Head->D_L!=NULL)
                        {
                        Head->D_L1=temp->D_L1;
                        }
                        else
                        {
                        Head->D_L=temp->D_L1;
                        }

                }

                if(temp->U_R1!=NULL)
                {
                        if(Head->U_R!=NULL)
                        {
                                Head->U_R1=temp->U_R1;
                        }
                        else
                        {
                        Head->U_R=temp->U_R1;
                        }

                }

                if(temp->U_L1!=NULL)
                {
                        if(Head->U_L!=NULL)
                        {
                        Head->U_L1=temp->U_L1;
                        }
                        else
                        {
                        Head->U_L=temp->U_L1;
                        }

                }


        if(Head->D_R!=NULL)
        join_small_length_nodes(Head,Head->D_R,1);

        if(Head->D_L!=NULL)
        join_small_length_nodes(Head,Head->D_L,2);

        if(Head->U_R!=NULL)
        join_small_length_nodes(Head,Head->U_R,3);

        if(Head->U_L!=NULL)
        join_small_length_nodes(Head,Head->U_L,4);

        if(Head->D_R1!=NULL)
        join_small_length_nodes(Head,Head->D_R1,5);

        if(Head->D_L1!=NULL)
        join_small_length_nodes(Head,Head->D_L1,6);

        if(Head->U_R1!=NULL)
        join_small_length_nodes(Head,Head->U_R1,7);

        if(Head->U_L1!=NULL)
        join_small_length_nodes(Head,Head->U_L1,8);


        }//end of if length is less than 5

        else
        {
        if(temp->D_R!=NULL)
        join_small_length_nodes(temp,temp->D_R,1);
        if(temp->D_L!=NULL)
        join_small_length_nodes(temp,temp->D_L,2);
        if(temp->U_R!=NULL)
        join_small_length_nodes(temp,temp->U_R,3);
        if(temp->U_L!=NULL)
        join_small_length_nodes(temp,temp->U_L,4);
        if(temp->D_R1!=NULL)
        join_small_length_nodes(temp,temp->D_R1,5);
        if(temp->D_L1!=NULL)
        join_small_length_nodes(temp,temp->D_L1,6);
        if(temp->U_R1!=NULL)
        join_small_length_nodes(temp,temp->U_R1,7);
        if(temp->U_L1!=NULL)
        join_small_length_nodes(temp,temp->U_L1,8);
        }



}

//end of function to join two nodes if the distance between the two
nodes is very small

//program to recognize one
int recognize_one(Node *Head)
{
float length;
float angle;

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);

Node *temp;

if(Head->D_R==NULL&&Head->D_L==NULL)
return(0);


if(Head->D_L!=NULL||Head->D_R!=NULL)
{
        if(Head->D_R!=NULL)
        temp=Head->D_R;
        else
        temp=Head->D_L;

        angle=calculate_angle(Head->x,Head->y,temp->x,temp->y);

        if((angle>=50&&angle<=90)||(angle<=-50&&angle>=-90))
        {
           if( check_subnodes(temp)==0)
           return(1);
           else
           return(0);
        }

}

}

//end of program to recognize one

//function to recognition J

int recognize_J(Node * Head)
{

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *temp);

Node *temp,*temp1,*temp2,*temp3,*temp4;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;

while(1)
{
if(check_one_subnode_only(Head)!=1)
return(0);

if(Head->D_R!=NULL)
temp=Head->D_R;
else
break;

if(temp->U_R!=NULL&&temp->D_R!=NULL)
{
temp1=temp->U_R;
temp2=temp->D_R;
}
else if(temp->U_R!=NULL&&temp->D_L!=NULL)
{
temp1=temp->U_R;
temp2=temp->D_L;
}
else if(temp->D_R!=NULL&&temp->D_R1!=NULL)
{
temp1=temp->D_R;
temp2=temp->D_R1;
}
else if(temp->D_R!=NULL&&temp->D_L!=NULL)
{
temp1=temp->D_R;
temp2=temp->D_L;
}
else
break;

if(temp2->D_L!=NULL)
temp3=temp2->D_L;
else
break;

if(check_one_subnode_only(temp2)!=1)
break;

while(temp3->D_L!=NULL)
{
temp3=temp3->D_L;
}

if(temp3->U_L!=NULL)
temp4=temp3->U_L;
else
break;

if(check_subnodes(temp4)==0)
return(1);
else
break;
}//end of while 1

return(0);




}
//end of program to recognize J

//program to recognize T

int recognize_T(Node * Head)
{
float length;
float angle;

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *temp);

Node *temp,*temp1,*temp2,*temp3,*temp4;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;

if(check_one_subnode_only(Head)!=1)
return(0);

while(1)
{

if(Head->D_R!=NULL)
temp=Head->D_R;
else
break;

if(temp->U_R!=NULL&&temp->D_R!=NULL)
{
temp1=temp->U_R;
temp2=temp->D_R;
}
else if(temp->U_R!=NULL &&temp->D_L!=NULL)
{
temp1=temp->U_R;
temp2=temp->D_L;
}
else if(temp->D_R!=NULL&&temp->D_R1!=NULL)
{
temp1=temp->D_R;
temp2=temp->D_R1;
}
else if(temp->D_R!=NULL&&temp->D_L!=NULL)
{
temp1=temp->D_R;
temp2=temp->D_L;
}
else
break;

if(check_subnodes(temp1)!=0)
break;

if(check_subnodes(temp2)!=0)
break;

return(1);

}//end of while


//begining of case 2
temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;

if(check_one_subnode_only(Head)!=1)
return(0);

while(1)
{

if(Head->D_L!=NULL)
temp=Head->D_L;
else
return(0);

if(temp->U_L!=NULL&&temp->D_R!=NULL)
{
temp1=temp->U_L;
temp2=temp->D_R;
}
else if(temp->U_L!=NULL &&temp->D_L!=NULL)
{
temp1=temp->U_L;
temp2=temp->D_L;
}
else if(temp->D_L!=NULL&&temp->D_L1!=NULL)
{
temp1=temp->D_L;
temp2=temp->D_L1;
}
else if(temp->D_L!=NULL&&temp->D_R!=NULL)
{
temp1=temp->D_L;
temp2=temp->D_R;
}
else
break;

if(check_subnodes(temp1)!=0)
break;

if(check_subnodes(temp2)!=0)
break;

return(1);

}//end of while

return(0);
} //end of program

//end of program to recognize T
//program to recognize four

int recognize_four(Node * Head)
{
float length;
float angle;

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *temp);

Node *temp,*temp1,*temp2,*temp3,*temp4;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;

if(check_one_subnode_only(Head)!=1)
return(0);

if((Head->D_R!=NULL)||(Head->D_L!=NULL))
{
        if(temp->D_R!=NULL)
          temp=Head->D_R;
        else
          temp=Head->D_L;
}
else
return(0);

if(check_one_subnode_only(temp)!=1)
return(0);

if((temp->D_R!=NULL)||(temp->U_R!=NULL))
{
        if(temp->D_R!=NULL)
        temp1=temp->D_R;
        else
        temp1=temp->U_R;
}
else
return(0);


if(check_one_subnode_only(temp1)==1)
{
        if((temp1->D_R!=NULL)||(temp1->U_R!=NULL))
        {
                if(temp1->D_R!=NULL)
                temp1=temp1->D_R;
                else
                temp1=temp1->U_R;
        }
        else
        return(0);

}

int count=0;

if(temp1->U_R!=NULL)
{
temp4=temp1->U_R;
count++;
}

if(temp1->U_R1!=NULL)
{
temp2=temp1->U_R1;
count++;
}

if(temp1->D_R!=NULL)
{
        if(temp2!=NULL)
        temp3=temp1->D_R;
        else
        temp2=temp1->D_R1;
count++;
}
if(temp1->D_R1!=NULL)
{
temp3=temp1->D_R;
count++;
}
if(temp1->D_L!=NULL)
{
temp3=temp1->D_L;
count++;
}

if(count!=3)
return(0);

if(temp2!=NULL&&temp3!=NULL&&temp4!=NULL)
return(1);
else
return(0);

}

//end of program to recognize four

//program to recognize four

int recognize_four1(Node * Head)
{

float length;
float angle;

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);

Node *temp,*temp1;

if(Head->D_R==NULL&&Head->D_L==NULL)
return(0);



//this is first looking for downward
if(Head->D_L!=NULL||Head->D_R!=NULL)
{
        if(Head->D_R!=NULL)
        temp=Head->D_R;
        else
        temp=Head->D_L;

        angle=calculate_angle(Head->x,Head->y,temp->x,temp->y);

        if((angle>=50&&angle<=90)||(angle<=-50&&angle>=-90))
        {
        }
        else
        {
        return(0);
        }
}
//end of looking for downward


if(temp->D_R!=NULL||temp->U_R!=NULL)
{
        if(Head->D_R!=NULL)
        {
        temp1=Head->D_R;
        }
        else
        {
        temp1=Head->D_L;
        }

        angle=calculate_angle(temp->x,temp->y,temp1->x,temp1->y);


        if((angle>=0&&angle<=20)||(angle>=-20&&angle<=0))
        {
        printf("recached second level in recognition four");
        }
        else
        {
        return(0);
        }

}





}

//end of the program to recognize four


//program to recognize seven

int recognize_seven(Node * Head)
{

float length;
float angle;

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *);

Node *temp,*temp1,*temp2,*temp3;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;


while(1)
{

if(Head->D_L!=NULL)
temp=Head->D_L;
else
{
        if(check_one_subnode_only(Head)!=1)
        break;
}

if(Head->D_R!=NULL)
temp1=Head->D_L;
else
break;

if(temp1!=NULL)
{
        if((temp1->D_L!=NULL)||(temp->D_R!=NULL))
        {
                if(temp1->D_L!=NULL)
                temp2=temp1->D_L;
                else
                temp2=temp1->D_R;
        }
        else
        break;
}
else
break;

if(temp!=NULL)
{
        if(check_subnodes(temp)!=0)
        {
          break;
        }
}


if(temp2!=NULL)
{
        if(check_subnodes(temp2)!=0)
        {
          break;
        }
}
else
break;

return(1);

}//end of while


temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;

//begining of case 2

while(1)
{
if(Head->D_L!=NULL)
temp=Head->D_L;
else
break;


        if((Head->D_L1!=NULL)||(Head->D_R!=NULL))
        {
                if(Head->D_L1!=NULL)
                temp1=Head->D_L1;
                else
                temp1=Head->D_R;
        }
        else
        break;


if(temp!=NULL)
{
        if(check_subnodes(temp)!=0)
        {
          break;
        }
}
else
break;

if(temp1!=NULL)
{
        if(check_subnodes(temp1)!=0)
        {
          break;
        }
}
else
break;

return(1);

}//end of while


temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;

//begining of case 3

while(1)
{
if(Head->D_R!=NULL)
temp1=Head->D_R;
else
break;


        if((temp1->D_L!=NULL)||(temp1->D_R!=NULL))
        {
                if(temp1->D_L!=NULL)
                temp2=temp1->D_L;
                else
                temp2=temp1->D_R;
        }
        else
        break;


if(temp2!=NULL)
{
        if(check_subnodes(temp2)!=0)
        {
          break;
        }
}
else
break;

return(1);

}//end of while

return(0);
}

//end of the program to recognize seveb

//program to recognize L

int recognize_L(Node * Head)
{

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *);


Node *temp,*temp1,*temp2,*temp3,*temp4,*temp5;

temp=NULL;
temp1=NULL;

if(check_one_subnode_only(Head)!=1)
return(0);

if(Head->D_L!=NULL||Head->D_R!=NULL)
{
        if(Head->D_L!=NULL)
        temp=Head->D_L;
        else
        temp=Head->D_R;
}
else
return(0);

if(check_one_subnode_only(temp)!=1)
return(0);

if(temp->U_R!=NULL||temp->D_R!=NULL)
{
        if(temp->U_R!=NULL)
        temp1=temp->U_R;
        else
        temp1=temp->D_R;
}
else
return(0);

if(check_subnodes(temp1)==0)
return(1);
else
return(0);

}
//end of program to recognize L

//program to recognize E

int recognize_E(Node * Head)
{

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *);


Node *temp,*temp1,*temp2,*temp3,*temp4,*temp5;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;
temp4=NULL;
temp5=NULL;


if(check_one_subnode_only(Head)!=1)
return(0);

if(Head->D_L!=NULL)
temp1=Head->D_L;
else
return(0);

if(temp1->D_L!=NULL||temp1->D_R!=NULL)
{
        if(temp1->D_L!=NULL)
        temp2=temp1->D_L;
        else
        temp2=temp1->D_R;
}
else
return(0);

if(check_one_subnode_only(temp2)==1)
return(0);

if(check_subnodes(temp2)==0)
return(0);

if(temp2->U_R!=NULL&&temp2->D_R!=NULL)
{
temp3=temp2->U_R;
temp4=temp2->D_R;
}
else if(temp2->D_R!=NULL&&temp2->D_R1!=NULL)
{
temp3=temp2->D_R;
temp4=temp2->D_R1;
}
else if(temp2->D_R!=NULL&&temp2->D_L!=NULL)
{
temp3=temp2->D_R;
temp4=temp2->D_L;
}
else
return(0);

if(check_one_subnode_only(temp2)!=1)
return(0);

if(temp4->U_R!=NULL||temp4->D_R!=NULL)
{
        if(temp4->U_R!=NULL)
        temp5=temp4->U_R;
        else
        temp5=temp4->D_R;
}
else
return(0);


if(check_subnodes(temp5)==0)
return(1);
else
return(0);

}
//end of program to recognize E

//program to recognize A

int recognize_A(Node * Head)
{

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *);


Node *temp,*temp1,*temp2,*temp3,*temp4,*temp5;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;
temp4=NULL;
temp5=NULL;


if(Head->D_L!=NULL)
temp=Head->D_L;
else
return(0);

if(temp->D_L!=NULL)
temp1=temp->D_L;
else
return(0);

if(temp->D_R!=NULL||temp->U_R!=NULL)
{
        if(temp->D_R!=NULL)
        temp2=temp->D_R;
        else
        temp2=temp->U_R;
}

if(check_subnodes(temp2)==0)
return(0);

if(check_one_subnode_only(temp2)==1)
{
        if(temp2->D_R!=NULL)
        temp2=temp2->D_R;
        else if(temp2->U_R!=NULL)
        temp2=temp2->U_R;
        else
        return(0);
}

if(temp2->U_L!=NULL)
temp4=temp2->U_L;
else
return(0);

if(temp2->D_R!=NULL)
temp3=temp2->D_R;
else
return(0);


return(1);

}
//end of program to recognize A

//program to recognize six

int recognize_six(Node * Head)
{

float length;
float angle;

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *);

Node *temp,*temp1,*temp2,*temp3,*temp4,*temp5,*temp6;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;
temp4=NULL;

while(1)
{
        if(Head->D_L!=NULL)
        temp1=Head->D_L;
        else
        break;

        if(check_one_subnode_only(temp1)!=1)
        break;


        if(temp1->D_L!=NULL)
        temp2=temp1->D_L;
        else
        break;

        while(1)
        {
                if(temp2->D_L!=NULL||temp2->U_R!=NULL)
                {
                        if(temp2->D_L!=NULL)
                        temp2=temp2->D_L;
                        else
                        {
                        temp3=temp2->U_R;
                        break;
                        }
                }
                else
                {
                temp3=NULL;
                break;
                }
        }

        if(temp3==NULL) //temp3 is set null to indicate that previous failed
        break;

        while(1)
        {
                if(temp3->U_R!=NULL||temp3->U_L!=NULL)
                {
                        if(temp3->U_R!=NULL)
                        temp3=temp3->U_R;
                        else
                        {
                        temp4=temp3->U_L;
                        break;
                        }
                }
                else
                {
                temp4=NULL;
                break;
                }
        }

        if(temp4==NULL) //temp3 is set null to indicate that previous failed
        break;


        while(1)
        {
                if(temp4->U_L!=NULL)
                {
                temp4=temp4->U_L;
                }
                else
                {
                break;
                }

        }

        if(temp4==NULL)
        break;
        else
        return(1);

        break;

}

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;
temp4=NULL;
temp5=NULL;
temp6=NULL;


if(Head->D_R!=NULL)
temp=Head->D_R;

if(Head->D_L!=NULL)
temp1=Head->D_L;
else
return(0);


if(check_one_subnode_only(temp1)!=1)
return(0);


while(1)
{
if(temp1->D_R!=NULL||temp1->D_L!=NULL)
{
        if(temp1->D_L!=NULL)
                temp1=temp1->D_L;
        else
        {
                temp2=temp1->D_R;
                break;
        }

}
else
return(0);
}//end of while this loop is if it continues with D_R only


if(check_one_subnode_only(temp2)!=1)
return(0);


while(1)
{
if(temp2->U_R!=NULL||temp2->D_R!=NULL)
{
        if(temp2->D_R!=NULL)
                temp2=temp2->D_R;
        else
        {
                temp3=temp2->U_R;
                break;
        }

}
else
return(0);
}//end of while this loop is if it continues with D_R only




if(check_one_subnode_only(temp3)!=1)
return(0);


while(1)
{
if(temp3->U_R!=NULL||temp3->U_L!=NULL)
{
        if(temp3->U_R!=NULL)
                temp3=temp3->U_R;
        else
        {
                temp4=temp3->U_L;
                break;
        }

}
else
return(0);
}//end of while this loop is if it continues with D_R only


if(check_one_subnode_only(temp4)!=1)
return(0);


while(1)
{
if(temp4->U_R!=NULL)
{
        temp4=temp4->U_R;
}
else
break;
}


return(1);
}


//begining of function to check if it is 3 or what

int recognize_three(Node * Head)
{
float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);
int check_one_subnode_only(Node *);

Node *temp,*temp1,*temp2,*temp3,*temp4,*temp5,*temp6;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;
temp4=NULL;
temp5=NULL;
temp6=NULL;

//this is the begining of case 1
while(1)
{

if(check_one_subnode_only(Head)==1)
{
        if(Head->D_R!=NULL)
                temp1=Head->D_R;
        else
                return(0);

}
else
return(0);

if(temp1->D_R!=NULL||temp1->D_L!=NULL)
{
        if(temp1->D_R!=NULL)
        temp2=temp1->D_R;
        else
        temp2=temp1->D_L;
}

if(temp2->D_L!=NULL&&temp2->D_L1!=NULL)
{
temp3=temp2->D_L1;
temp4=temp2->D_L;
}
else if(temp2->D_L!=NULL&&temp2->U_L!=NULL)
{
temp3=temp2->U_L;
temp4=temp2->D_L;
}
else if(temp2->D_R!=NULL&&temp2->D_L!=NULL)
{
temp3=temp2->D_L;
temp4=temp2->D_R;
}
else if(temp2->D_R!=NULL && temp2->U_L!=NULL)
{
temp3=temp2->U_L;
temp4=temp2->D_R;
}
else
return(0);

if(check_subnodes(temp4)==0)
{
//swapping
temp5=temp4;
temp4=temp3;
temp3=temp5;
}


if(temp4->D_L!=NULL||temp4->U_L!=NULL)
{
        if(temp4->D_L!=NULL)
        temp5=temp4->D_L;
        else
        temp5=temp4->U_L;
}
else
return(0);


return(1);
} //end of while
//this is the end of case 1


}

//end of function to check if it is 3 or what

//begining of function to check if it is 5 or what

int recognize_five(Node * Head)
{

float calculate_angle(int,int,int,int);
int check_subnodes(Node *temp);

Node *temp,*temp1,*temp2,*temp3,*temp4,*temp5,*temp6;

temp=NULL;
temp1=NULL;
temp2=NULL;
temp3=NULL;
temp4=NULL;
temp5=NULL;
temp6=NULL;


if(Head->D_L!=NULL)
temp=Head->D_L;
else
return(0);

if(temp->D_L!=NULL||temp->D_R!=NULL)
{
if(temp->D_L!=NULL)
temp1=temp->D_L;
else
temp1=temp->D_R;
}
else
return(0);


if(temp1->D_R!=NULL||temp1->U_R!=NULL)
{
if(temp1->D_R!=NULL)
temp2=temp1->D_R;
else
temp2=temp1->U_R;
}
else
return(0);


if(temp2->D_R!=NULL||temp2->D_L!=NULL)
{
        if(temp2->D_R!=NULL)
        temp3=temp2->D_R;
        else
        temp4=temp2->D_R;
}
else
return(0);

if(temp3!=NULL)
{
        if(temp3->D_L!=NULL)
        temp4=temp3->D_L;
        else
        return(0);
}

if(temp4->D_L!=NULL||temp4->U_L!=NULL)
{
        if(temp4->D_L!=NULL)
        temp5=temp4->D_L;
        else
        temp5=temp4->U_L;
}
else
return(0);


return(1);

}

//end of function to check if it is 5 or what



//to check if the node has any subnodes
int check_subnodes(Node *temp)
{
if(temp->U_R==NULL&&temp->U_L==NULL&&temp->D_R==NULL&&temp->D_L==NULL&&temp->U_R1==NULL&&temp->U_L1==NULL&&temp->D_R1==NULL&&temp->D_L1==NULL)
return(0);
else
return(1);
}
//end of to check if node has any subnodes


//function to calculate angle if two node are given

float calculate_length(int x1,int y1,int x2,int y2)
{
return(sqrt((float)(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}
//end of function to calculate angle if two nodes are given


//function to calcuate angle betweeen two nodes is given by
float calculate_angle(int x1,int y1,int x2,int y2)
{

float theta;

if((x1==x2)&&(y1==y2))   //this is found from testing so don't change
theta=0;
else if(x1!=x2)
{
        theta= atan(float(float (y1)-y2)/(x1-x2));
        theta=(theta*180)/3.142;
}
else
{
theta=90;
}

return(theta);
}
//end of function to calculate angle between two nodes

//function for putting a string into an array
void write(char arr[],char file[])
{
FILE *f;

f=fopen(file,"a");
fputs(arr,f);
fputs("\n",f);
fclose(f);
}

//end of function of putting a string into an array

//algorithm for traversing the structure thus formed by moving over
the algorithm

void traverse(Node * Head,int m,int &pos,char arr[] )
{
if(Head!=NULL)
{
if(m==0)
{
printf("a");    //start
arr[pos++]='a';
}

if(m==1)
{
printf("b");     //hleft
arr[pos++]='b';
}

if(m==2)
{
printf("c");       //vdown
arr[pos++]='c';
}

if(m==3)
{
printf("d");            //hright
arr[pos++]='d';
}

if(m==4)
{
printf("e");       //vup
arr[pos++]='e';
}


        if(Head->D_L!=NULL)
        traverse(Head->D_L,1,pos,arr);

        if(Head->D_R!=NULL)
        traverse(Head->D_R,2,pos,arr);

        if(Head->U_R!=NULL)
        traverse(Head->U_R,3,pos,arr);

        if(Head->U_L!=NULL)
        traverse(Head->U_L,4,pos,arr);

}

}

//end of traversing the structure  created by the tree


void draw_graph(Node * Head,int m,int &pos,char arr[],int x,int y )
{
float angle;
angle=calculate_angle(x,y,Head->x,Head->y);
gotoxy(24,24);
cout<<"angle="<<angle<<"     "<<endl;
getch();

if(Head!=NULL)
{
if(m==0)
{
printf("a");    //start
arr[pos++]='a';
}

if(m==1)
{

if(abs(x-Head->x)>3||abs(y-Head->y)>3)
{
printf("b");     //hleft
arr[pos++]='b';
line(x,y,Head->x,Head->y);
}

}

if(m==2)
{

if(abs(x-Head->x)>3||abs(y-Head->y)>3)
{
printf("c");       //vdown
arr[pos++]='c';
line(x,y,Head->x,Head->y);
}
}

if(m==3)
{
if(abs(x-Head->x)>3||abs(y-Head->y)>3)
{
printf("d");            //hright
arr[pos++]='d';
line(x,y,Head->x,Head->y);
}
}

if(m==4)
{
if((abs(x-(Head->x))>3)||(abs(y-Head->y)>3))
{
printf("e");       //vup
arr[pos++]='e';
line(x,y,Head->x,Head->y);
}
}


        if(Head->D_L!=NULL)
        draw_graph(Head->D_L,1,pos,arr,Head->x,Head->y);

        if(Head->D_R!=NULL)
        draw_graph(Head->D_R,2,pos,arr,Head->x,Head->y);

        if(Head->U_R!=NULL)
        draw_graph(Head->U_R,3,pos,arr,Head->x,Head->y);

        if(Head->U_L!=NULL)
        draw_graph(Head->U_L,4,pos,arr,Head->x,Head->y);

        if(Head->D_L1!=NULL)
        draw_graph(Head->D_L1,1,pos,arr,Head->x,Head->y);

        if(Head->D_R1!=NULL)
        draw_graph(Head->D_R1,2,pos,arr,Head->x,Head->y);

        if(Head->U_R1!=NULL)
        draw_graph(Head->U_R1,3,pos,arr,Head->x,Head->y);

        if(Head->U_L1!=NULL)
        draw_graph(Head->U_L1,4,pos,arr,Head->x,Head->y);

}

}

//end of traversing the structure  created by the tree

//program to check if node contains only one subnode
int check_one_subnode_only(Node *temp)
{
if((temp->U_R!=NULL)&&(temp->U_L==NULL)&&(temp->D_R==NULL)&&(temp->D_L==NULL)&&(temp->U_R1==NULL)&&(temp->U_L1==NULL)&&(temp->D_R1==NULL)&&(temp->D_L1==NULL))
return(1);
if((temp->U_R==NULL)&&(temp->U_L!=NULL)&&(temp->D_R==NULL)&&(temp->D_L==NULL)&&(temp->U_R1==NULL)&&(temp->U_L1==NULL)&&(temp->D_R1==NULL)&&(temp->D_L1==NULL))
return(1);
if((temp->U_R==NULL)&&(temp->U_L==NULL)&&(temp->D_R!=NULL)&&(temp->D_L==NULL)&&(temp->U_R1==NULL)&&(temp->U_L1==NULL)&&(temp->D_R1==NULL)&&(temp->D_L1==NULL))
return(1);
if((temp->U_R==NULL)&&(temp->U_L==NULL)&&(temp->D_R==NULL)&&(temp->D_L!=NULL)&&(temp->U_R1==NULL)&&(temp->U_L1==NULL)&&(temp->D_R1==NULL)&&(temp->D_L1==NULL))
return(1);
if((temp->U_R==NULL)&&(temp->U_L==NULL)&&(temp->D_R==NULL)&&(temp->D_L==NULL)&&(temp->U_R1!=NULL)&&(temp->U_L1==NULL)&&(temp->D_R1==NULL)&&(temp->D_L1==NULL))
return(1);
if((temp->U_R==NULL)&&(temp->U_L==NULL)&&(temp->D_R==NULL)&&(temp->D_L==NULL)&&(temp->U_R1==NULL)&&(temp->U_L1!=NULL)&&(temp->D_R1==NULL)&&(temp->D_L1==NULL))
return(1);
if((temp->U_R==NULL)&&(temp->U_L==NULL)&&(temp->D_R==NULL)&&(temp->D_L==NULL)&&(temp->U_R1==NULL)&&(temp->U_L1==NULL)&&(temp->D_R1!=NULL)&&(temp->D_L1==NULL))
return(1);
if((temp->U_R==NULL)&&(temp->U_L==NULL)&&(temp->D_R==NULL)&&(temp->D_L==NULL)&&(temp->U_R1==NULL)&&(temp->U_L1==NULL)&&(temp->D_R1==NULL)&&(temp->D_L1!=NULL))
return(1);

return(0);
}
//end of program to check if node contains only one subnode

//program to remove the 0----0-----0 things in the graph

void minimize_graph(Node *Head,Node *temp,int which_dir)
{
float angle1,angle2,diff;

void minimize_graph(Node *,Node *,int);
int check_one_subnode_only(Node *);
float calculate_length(int,int,int,int);

        if(temp==NULL)
        return;

Node *temp1;

        int angle_diff;

        if(check_one_subnode_only(temp)==0)
        {
        minimize_graph(temp,temp->D_L,1);
        minimize_graph(temp,temp->D_R,2);
        minimize_graph(temp,temp->U_R,3);
        minimize_graph(temp,temp->U_L,4);
        minimize_graph(temp,temp->D_L1,5);
        minimize_graph(temp,temp->D_R1,6);
        minimize_graph(temp,temp->U_R1,7);
        minimize_graph(temp,temp->U_L1,8);
        return;
        }

        if((temp->D_L!=NULL)&&(which_dir==1))
        {
            temp1=temp->D_L;

                angle1=calculate_angle(Head->x,Head->y,temp->x,temp->y);
                angle2=calculate_angle(temp->x,temp->y,temp1->x,temp1->y);

                angle_diff=abs((abs(angle1))-(abs(angle2)));


                if(angle_diff>=0&&angle_diff<=30)
                {
                Head->D_L=temp->D_L;
                minimize_graph(Head,Head->D_L,1);
                }
                else
                {
                minimize_graph(temp,temp->D_L,1);
                }

        }

        else if((temp->D_R!=NULL)&&(which_dir==2))
        {

            temp1=temp->D_R;

                angle1=calculate_angle(Head->x,Head->y,temp->x,temp->y);
                angle2=calculate_angle(temp->x,temp->y,temp1->x,temp1->y);

                angle_diff=abs((abs(angle1))-(abs(angle2)));


                if(angle_diff>=0&&angle_diff<=30)
                {
                Head->D_R=temp->D_R;
                minimize_graph(Head,temp->D_R,2);
                }
                else
                {
                minimize_graph(temp,temp->D_R,2);
                }

        }
        else if((temp->U_R!=NULL)&&(which_dir==3))
        {
            temp1=temp->U_R;

                angle1=(Head->x,Head->y,temp->x,temp->y);
                angle2=(temp->x,temp->y,temp1->x,temp1->y);

                angle_diff=abs(abs(angle1))-(abs(angle2));


                if(angle_diff>=0&&angle_diff<=30)
                {
                Head->U_R=temp->U_R;
                minimize_graph(Head,temp->U_R,3);
                }
                else
                {
                minimize_graph(temp,temp->U_R,3);
                }

        }
        else if((temp->U_L!=NULL)&&(which_dir==4))
        {
            temp1=temp->U_L;

                angle1=(Head->x,Head->y,temp->x,temp->y);
                angle2=(temp->x,temp->y,temp1->x,temp1->y);

                angle_diff=abs(abs(angle1))-(abs(angle2));


                if(angle_diff>=0&&angle_diff<=30)
                {
                Head->U_L=temp->U_L;
                minimize_graph(Head,temp->U_L,4);
                }
                else
                {
                minimize_graph(temp,temp->U_L,4);
                }

        }
        else if((temp->D_L1!=NULL)&&(which_dir==5))
        {
            temp1=temp->D_L1;

                angle1=(Head->x,Head->y,temp->x,temp->y);
                angle2=(temp->x,temp->y,temp1->x,temp1->y);

                angle_diff=abs(abs(angle1))-(abs(angle2));


                if(angle_diff>=0&&angle_diff<=30)
                {
                Head->D_L1=temp->D_L1;
                minimize_graph(Head,temp->D_L1,1);
                }
                else
                {
                minimize_graph(temp,temp->D_L1,1);
                }

        }
        else if((temp->D_R1!=NULL)&&(which_dir==2))
        {
            temp1=temp->D_R1;

                angle1=(Head->x,Head->y,temp->x,temp->y);
                angle2=(temp->x,temp->y,temp1->x,temp1->y);

                angle_diff=abs(abs(angle1))-(abs(angle2));


                if(angle_diff>=0&&angle_diff<=30)
                {
                Head->D_R1=temp->D_R1;
                minimize_graph(Head,temp->D_R1,2);
                }
                else
                {
                minimize_graph(temp,temp->D_R,2);
                }

        }
        else if((temp->U_R1!=NULL)&&(which_dir==3))
        {
            temp1=temp->U_R1;

                angle1=(Head->x,Head->y,temp->x,temp->y);
                angle2=(temp->x,temp->y,temp1->x,temp1->y);

                angle_diff=abs(abs(angle1))-(abs(angle2));


                if(angle_diff>=0&&angle_diff<=30)
                {
                Head->U_R1=temp->U_R1;
                minimize_graph(Head,temp->U_R1,3);
                }
                else
                {
                minimize_graph(temp,temp->U_R1,3);
                }

        }
        else if((temp->U_L1!=NULL)&&(which_dir==4))
        {
            temp1=temp->U_L1;

                angle1=(Head->x,Head->y,temp->x,temp->y);
                angle2=(temp->x,temp->y,temp1->x,temp1->y);

                angle_diff=abs(abs(angle1))-(abs(angle2));


                if(angle_diff>=0&&angle_diff<=30)
                {
                Head->U_L1=temp->U_L1;
                minimize_graph(Head,temp->U_L1,4);
                }
                else
                {
                minimize_graph(temp,temp->U_L1,4);
                }

        }
        else if(temp->D_L!=NULL)
        {
        minimize_graph(temp,temp->D_L,1);
        }
        else if(temp->D_R!=NULL)
        {
        minimize_graph(temp,temp->D_R,2);
        }
        else if(temp->U_R!=NULL)
        {
        minimize_graph(temp,temp->U_R,3);
        }
        else if(temp->U_L!=NULL)
        {
        minimize_graph(temp,temp->U_L,4);
        }
        else if(temp->D_L1!=NULL)
        {
        minimize_graph(temp,temp->D_L1,1);
        }
        else if(temp->D_R1!=NULL)
        {
        minimize_graph(temp,temp->D_R1,2);
        }
        else if(temp->U_R1!=NULL)
        {
        minimize_graph(temp,temp->U_R1,3);
        }
        else if(temp->U_L1!=NULL)
        {
        minimize_graph(temp,temp->U_L1,4);
        }


}

//end of program to remove the 0----0-----0 things in the graph

//program to remove the 0----0-----0 things in the graph using the
length parameter

void minimize_graph_length(Node *Head,Node *temp)
{
float length1,length2;
Node *temp1;

void minimize_graph_length(Node *,Node *);
int check_one_subnode_only(Node *);
float calculate_length(int,int,int,int);

        if(temp==NULL)
        return;


        if(check_one_subnode_only(temp)==0)
        {
        minimize_graph_length(temp,temp->D_L);
        minimize_graph_length(temp,temp->D_R);
        minimize_graph_length(temp,temp->U_R);
        minimize_graph_length(temp,temp->U_L);
        minimize_graph_length(temp,temp->D_L1);
        minimize_graph_length(temp,temp->D_R1);
        minimize_graph_length(temp,temp->U_R1);
        minimize_graph_length(temp,temp->U_L1);
        return;
        }

        if(temp->D_L!=NULL)
        {
        temp1=temp->D_L;

                length1=calculate_length(Head->x,Head->y,temp->x,temp->y);
                length2=calculate_length(temp->x,temp->y,temp1->x,temp1->y);

                if(length1<5||length2<5)
                {
                Head->D_L=temp->D_L;
                minimize_graph_length(Head,Head->D_L);
                }
                else
                {
                minimize_graph_length(temp,temp->D_L);
                }

        }

        else if((temp->D_R!=NULL))
        {
        temp1=temp->D_R;

                length1=calculate_length(Head->x,Head->y,temp->x,temp->y);
                length2=calculate_length(temp->x,temp->y,temp1->x,temp1->y);

                if(length1<5||length2<5)
                {
                Head->D_R=temp->D_R;
                minimize_graph_length(Head,Head->D_R);
                }
                else
                {
                minimize_graph_length(temp,temp->D_R);
                }

        }
        else if((temp->U_R!=NULL))
        {
        temp1=temp->U_R;

                length1=calculate_length(Head->x,Head->y,temp->x,temp->y);
                length2=calculate_length(temp->x,temp->y,temp1->x,temp1->y);

                if(length1<5||length2<5)
                {
                Head->U_R=temp->U_R;
                minimize_graph_length(Head,Head->U_R);
                }
                else
                {
                minimize_graph_length(temp,temp->U_R);
                }

        }
        else if((temp->U_L!=NULL))
        {
        temp1=temp->U_L;

                length1=calculate_length(Head->x,Head->y,temp->x,temp->y);
                length2=calculate_length(temp->x,temp->y,temp1->x,temp1->y);

                if(length1<5||length2<5)
                {
                Head->U_L=temp->U_L;
                minimize_graph_length(Head,Head->U_L);
                }
                else
                {
                minimize_graph_length(temp,temp->U_L);
                }
        }
        else if((temp->D_L1!=NULL))
        {
        temp1=temp->D_L1;

                length1=calculate_length(Head->x,Head->y,temp->x,temp->y);
                length2=calculate_length(temp->x,temp->y,temp1->x,temp1->y);

                if(length1<5||length2<5)
                {
                Head->D_L1=temp->D_L1;
                minimize_graph_length(Head,Head->D_L1);
                }
                else
                {
                minimize_graph_length(temp,temp->D_L1);
                }
        }
        else if((temp->D_R1!=NULL))
        {

        temp1=temp->D_R1;

                length1=calculate_length(Head->x,Head->y,temp->x,temp->y);
                length2=calculate_length(temp->x,temp->y,temp1->x,temp1->y);

                if(length1<5||length2<5)
                {
                Head->D_R1=temp->D_R1;
                minimize_graph_length(Head,Head->D_R1);
                }
                else
                {
                minimize_graph_length(temp,temp->D_R1);
                }
        }
        else if((temp->U_R1!=NULL))
        {
        temp1=temp->U_R1;

                length1=calculate_length(Head->x,Head->y,temp->x,temp->y);
                length2=calculate_length(temp->x,temp->y,temp1->x,temp1->y);

                if(length1<5||length2<5)
                {
                Head->U_R1=temp->U_R1;
                minimize_graph_length(Head,Head->U_R1);
                }
                else
                {
                minimize_graph_length(temp,temp->U_R1);
                }
        }
        else if((temp->U_L1!=NULL))
        {

        temp1=temp->U_L1;

                length1=calculate_length(Head->x,Head->y,temp->x,temp->y);
                length2=calculate_length(temp->x,temp->y,temp1->x,temp1->y);

                if(length1<5||length2<5)
                {
                Head->U_L1=temp->U_L1;
                minimize_graph_length(Head,Head->U_L1);
                }
                else
                {
                minimize_graph_length(temp,temp->U_L1);
                }
        }

}

//end of program to remove the 0----0-----0 things in the graph


//program to merge two nodes based upong the length of the nodes
/*
void minimize_graph_on_length(Node *Head,Node *temp)
{

void minimize_graph_on_length(Node *,Node *);
int check_one_subnode_only(Node *);

        if(temp==NULL)
        return;

Node *temp1;

        int angle_diff;

        if(check_one_subnode_only(temp)==0)
        {
        minimize_graph(temp,temp->D_L,1);
        minimize_graph(temp,temp->D_R,2);
        minimize_graph(temp,temp->U_R,3);
        minimize_graph(temp,temp->U_L,4);
        minimize_graph(temp,temp->D_L1,1);
        minimize_graph(temp,temp->D_R1,2);
        minimize_graph(temp,temp->U_R1,3);
        minimize_graph(temp,temp->U_L1,4);
        return;
        }

        if((temp->D_L!=NULL)&&(which_dir==1))
        {
                Head->D_L=temp->D_L;
                minimize_graph(Head,Head->D_L,1);
        }
        else if((temp->D_R!=NULL)&&(which_dir==2))
        {
                Head->D_R=temp->D_R;
                minimize_graph(Head,Head->D_R,2);
        }
        else if((temp->U_R!=NULL)&&(which_dir==3))
        {
                Head->U_R=temp->U_R;
                minimize_graph(Head,Head->U_R,3);
        }
        else if((temp->U_L!=NULL)&&(which_dir==4))
        {
                Head->U_L=temp->U_L;
                minimize_graph(Head,Head->U_L,4);
        }
        else if((temp->D_L1!=NULL)&&(which_dir==1))
        {
                Head->D_L1=temp->D_L1;
                minimize_graph(Head,Head->D_L1,1);
        }
        else if((temp->D_R1!=NULL)&&(which_dir==2))
        {
                Head->D_R1=temp->D_R1;
                minimize_graph(Head,Head->D_R1,2);
        }
        else if((temp->U_R1!=NULL)&&(which_dir==3))
        {
                Head->U_R1=temp->U_R1;
                minimize_graph(Head,Head->U_R1,3);
        }
        else if((temp->U_L1!=NULL)&&(which_dir==4))
        {
                Head->U_L1=temp->U_L1;
                minimize_graph(Head,Head->U_L1,4);
        }
        else if(temp->D_L!=NULL)
        {
        minimize_graph(temp,temp->D_L,1);
        }
        else if(temp->D_R!=NULL)
        {
        minimize_graph(temp,temp->D_R,2);
        }
        else if(temp->U_R!=NULL)
        {
        minimize_graph(temp,temp->U_R,3);
        }
        else if(temp->U_L!=NULL)
        {
        minimize_graph(temp,temp->U_L,4);
        }
        else if(temp->D_L1!=NULL)
        {
        minimize_graph(temp,temp->D_L1,1);
        }
        else if(temp->D_R1!=NULL)
        {
        minimize_graph(temp,temp->D_R1,2);
        }
        else if(temp->U_R1!=NULL)
        {
        minimize_graph(temp,temp->U_R1,3);
        }
        else if(temp->U_L1!=NULL)
        {
        minimize_graph(temp,temp->U_L1,4);
        }


}

//end of program to remove the 0----0-----0 things in the graph

*/

//function to clear the that copy backs the contents area

void copyback(int xmin,int ymin,int xmax,int ymax,int newx,int newy)
{
int i,j;

for(i=ymin;i<ymax;i++)
{
        for(j=xmin;j<xmax;j++)
        {
        putpixel(j,i,getpixel(newx+j,newy+i));
        }
}
}
//end of fucntion the

//begining of the copy function
void copy(int xmin,int ymin,int xmax,int ymax,int newx,int newy)
{
int i,j,c;

for(i=ymin;i<ymax;i++)
{
        for(j=xmin;j<xmax;j++)
        {

        if((c=getpixel(j,i))!=0)
                {
                putpixel(newx+j,newy+i,c);
                }
        }
}

}

//end of the function copy

//begining of the function finding x and y position for starting the
scanning
void find_xpos_ypos(int &x,int &y)
{
int i,j;
int c=0;

for(i=51;i<=99;i++)
{

for(j=51;j<=99;j++)
{
if(getpixel(j,i)!=0)
{
c=1;
break;
}
}
if(c==1)
break;

}
x=j;
y=i;
}

//end of function for finding x and y position for starting scanning

//this algorithm is to see whether that string is present in that
particular file

int find(char string[],char filename[])
{
int i,j;
FILE *f;
char ch;
char arr[30];
f=fopen(filename,"r");

if(f==NULL)
//printf("error opening file");


i=0;
while((ch=fgetc(f))!=EOF)
{
if(ch!='\n')
{
arr[i++]=ch;
}       //end of if
else
{
arr[i++]='\0';
arr[i++]='\0';
arr[i]='\0';


i=0;
        if(strcmp(arr,string)==0)
        {
        fclose(f);
        return(1);
        }
}//end of else
}
fclose(f);
return(0);
}


//end of function find

//function for moving over the writen content drawing as bar
void movewithangle2(int x,int y,int xint,int yint,int pos,Node * Head)
{

void movewithangle2(int,int,int,int,int,Node *);
void copy_node_to_temp(Node *,copy_node*);
Node * make_node(int,int,int,int,Node **);
int compare_two_copynode(copy_node,copy_node);
void make_adjustment(Node *,int,int,int);
Node *return_the_new_changed_Head(Node *,int);


float angle(int,int,int);


float ang;
ang=angle(320+x,120+y,1);

gotoxy(3,23);
cout<<"0000000000000";
gotoxy(3,23);
cout<<ang;

int xdis,ydis;


if((abs(xint-x)<MAX_VAL)||(abs(yint-y)<MAX_VAL))
{
}
else if(((ang>=60&&ang<=90)||(ang<=-60&&ang>=-90)))  //pos==2 then it
is in this range only
{
        if(pos==0||pos==1)
        {
        make_node(x,y,xint,yint,&Head);
        xint=x;
        yint=y;
        pos=2;
        }

}
else if(((ang>=0&&ang<=30)||(ang<=0&&ang>=-30)))  //pos==0 then it is
in this range
{


        if(pos==1||pos==2)
        {
        make_node(x,y,xint,yint,&Head);
        xint=x;
        yint=y;
        pos=0;
        }
}
else
{
        if(pos==2||pos==0)     //pos==1 then it is in this range
        {
        make_node(x,y,xint,yint,&Head);
        xint=x;
        yint=y;
        pos=1;
        }

}



putpixel(x,y,0);
gotoxy(23,22);
cout<<x;
gotoxy(23,23);
cout<<y;

gotoxy(1,1);
cout<<pos;
getch();


int passed=0;

// this if for removein side ways
int xchange,ychange;


//this part of the code is to keep which is the begining node
Node *Main_Head,*Main_Head1;
Main_Head=Head;
Main_Head1=Head;
//end of this part



copy_node temp1,temp2;

copy_node_to_temp(Main_Head,&temp1);
int which_dir;

if(getpixel(x-1,y)!=0)
{
        passed=1;
        putpixel(x-1,y,0);
        movewithangle2(x-1,y,xint,yint,pos,Head);
        xchange=x-1;
        ychange=y;
}

if(getpixel(x+1,y)!=0)
{
        if(passed==1)
        {
        putpixel(x+1,y,0);
        copy_node_to_temp(Main_Head,&temp2);
        which_dir=compare_two_copynode(temp1,temp2);

                if(which_dir!=0)
                {
                make_adjustment(Main_Head,which_dir,xchange,ychange);
                Head=return_the_new_changed_Head(Main_Head,which_dir);
                Main_Head=Main_Head1;
//              copy_node_to_temp(Head,&temp1);
                }

        movewithangle2(x+1,y,xchange,ychange,pos,Head);
        }
        else
        {
        passed=1;
        movewithangle2(x+1,y,xint,yint,pos,Head);
        xchange=x+1;
        ychange=y;
        }
}

if(getpixel(x-1,y-1)!=0)
{
        if(passed==1)
        {
        copy_node_to_temp(Main_Head,&temp2);
        which_dir=compare_two_copynode(temp1,temp2);

                if(which_dir!=0)
                {
                make_adjustment(Main_Head,which_dir,xchange,ychange);
                Head=return_the_new_changed_Head(Main_Head,which_dir);
                Main_Head=Main_Head1;
//              copy_node_to_temp(Head,&temp1);
                }
        movewithangle2(x-1,y-1,xchange,ychange,pos,Head);
        }
        else
        {
        passed=1;
        movewithangle2(x-1,y-1,xint,yint,pos,Head);
        xchange=x-1;
        ychange=y-1;
        }
}

if(getpixel(x+1,y-1)!=0)
{
        if(passed==1)
        {
        copy_node_to_temp(Main_Head,&temp2);
        which_dir=compare_two_copynode(temp1,temp2);

        if(which_dir!=0)
        {
        make_adjustment(Main_Head,which_dir,xchange,ychange);
        Head=return_the_new_changed_Head(Main_Head,which_dir);
        Main_Head=Main_Head1;
//      copy_node_to_temp(Head,&temp1);
        }
        movewithangle2(x+1,y-1,xchange,ychange,pos,Head);
        }
        else
        {
        passed=1;
        movewithangle2(x+1,y-1,xint,yint,pos,Head);
        xchange=x+1;
        ychange=y-1;
        }
}

if(getpixel(x-1,y+1)!=0)
{
        if(passed==1)
        {
        copy_node_to_temp(Main_Head,&temp2);
        which_dir=compare_two_copynode(temp1,temp2);

                if(which_dir!=0)
                {
                make_adjustment(Main_Head,which_dir,xchange,ychange);
                Head=return_the_new_changed_Head(Main_Head,which_dir);
                Main_Head=Main_Head1;
//              copy_node_to_temp(Head,&temp1);
                }
        movewithangle2(x-1,y+1,xchange,ychange,pos,Head);
        }
        else
        {
        passed=1;
        movewithangle2(x-1,y+1,xint,yint,pos,Head);
        xchange=x-1;
        ychange=y+1;
        }
}


if(getpixel(x+1,y+1)!=0)
{
        if(passed==1)
        {
        copy_node_to_temp(Main_Head,&temp2);
        which_dir=compare_two_copynode(temp1,temp2);

                if(which_dir!=0)
                {
                make_adjustment(Main_Head,which_dir,xchange,ychange);
                Head=return_the_new_changed_Head(Main_Head,which_dir);
                Main_Head=Main_Head1;
//              copy_node_to_temp(Head,&temp1);
                }
        movewithangle2(x+1,y+1,xchange,ychange,pos,Head);
        }
        else
        {
        passed=1;
        movewithangle2(x+1,y+1,xint,yint,pos,Head);
        xchange=x+1;
        ychange=y+1;
        }
}

if(getpixel(x,y-1)!=0)
{
        if(passed==1)
        {
        copy_node_to_temp(Main_Head,&temp2);
        which_dir=compare_two_copynode(temp1,temp2);

                if(which_dir!=0)
                {
                make_adjustment(Main_Head,which_dir,xchange,ychange);
                Head=return_the_new_changed_Head(Main_Head,which_dir);
                Main_Head=Main_Head1;
//              copy_node_to_temp(Head,&temp1);
                }

        movewithangle2(x,y-1,xchange,ychange,pos,Head);
        }
        else
        {
        passed=1;
        movewithangle2(x,y-1,xint,yint,pos,Head);
        xchange=x;
        ychange=y-1;
        }
}

if(getpixel(x,y+1)!=0)
{
        if(passed==1)
        {
        copy_node_to_temp(Main_Head,&temp2);
        which_dir=compare_two_copynode(temp1,temp2);

                if(which_dir!=0)
                {
                make_adjustment(Main_Head,which_dir,xchange,ychange);
                Head=return_the_new_changed_Head(Main_Head,which_dir);
                Main_Head=Main_Head1;
//              copy_node_to_temp(Head,&temp1);
                }
        movewithangle2(x,y+1,xchange,ychange,pos,Head);
        }
        else
        {
        passed=1;
        movewithangle2(x,y+1,xint,yint,pos,Head);
        }
}


if(abs(xint-x)<3&&abs(yint-y)<3)
{
}
else if(passed==0)
{
make_node(x,y,xint,yint,&Head);
}

}
//end of function of moving over the written part

//function to copy the characterisic of node into temporary structure

void copy_node_to_temp(Node * Head,copy_node *temp)
{
if(Head->U_R!=NULL)
temp->u_r=1;
else
temp->u_r=0;


if(Head->U_L!=NULL)
temp->u_l=1;
else
temp->u_l=0;


if(Head->D_R!=NULL)
temp->d_r=1;
else
temp->d_r=0;


if(Head->D_L!=NULL)
temp->d_l=1;
else
temp->d_l=0;

if(Head->U_R1!=NULL)
temp->u_r1=1;
else
temp->u_r1=0;


if(Head->U_L1!=NULL)
temp->u_l1=1;
else
temp->u_l1=0;


if(Head->D_R1!=NULL)
temp->d_r1=1;
else
temp->d_r1=0;


if(Head->D_L1!=NULL)
temp->d_l1=1;
else
temp->d_l1=0;

}

//end of function to copy the characterisic of node into temporary
structure


//function to compare to copynode
int compare_two_copynode(copy_node temp1,copy_node temp2)
{

if(temp1.u_r!=temp2.u_r)
{
gotoxy(5,10);
printf("which_dir=1");
return(1);
}

else if(temp1.u_l!=temp2.u_l)
{
gotoxy(5,10);
printf("which_dir=2");
return(2);
}
else if(temp1.d_r!=temp2.d_r)
{
gotoxy(5,10);
printf("which_dir=3");
return(3);
}
else if(temp1.d_l!=temp2.d_l)
{
gotoxy(5,10);
printf("which_dir=4");
return(4);
}
else if(temp1.u_r1!=temp2.u_r1)
{
gotoxy(5,10);
printf("which_dir=1");
return(5);
}

else if(temp1.u_l1!=temp2.u_l1)
{
gotoxy(5,10);
printf("which_dir=2");
return(6);
}
else if(temp1.d_r1!=temp2.d_r1)
{
gotoxy(5,10);
printf("which_dir=3");
return(7);
}
else if(temp1.d_l1!=temp2.d_l1)
{
gotoxy(5,10);
printf("which_dir=4");
return(8);
}
else
{
gotoxy(5,10);
printf("which_dir=0");
return(0);
}

}
//end of function copynode

//function to return the new head position
Node * return_the_new_changed_Head(Node *Head,int which_dir)
{
if(which_dir==1)
return(Head->U_R);
else if(which_dir==2)
return(Head->U_L);
else if(which_dir==3)
return(Head->D_R);
else if(which_dir==4)
return(Head->D_L);
else if(which_dir==5)
return(Head->U_R1);
else if(which_dir==6)
return(Head->U_L1);
else if(which_dir==7)
return(Head->D_R1);
else if(which_dir==8)
return(Head->D_L1);
else
return(Head);
}
//end of function to return the new Head position

//function to make the adjustment base on the value which direction is
not equal

void make_adjustment(Node *Head,int which_dir,int xchange,int ychange)
{
Node *temp2,*temp1;
Node * Main_Head;
Node *make_node(int x,int y,int xint,int yint,Node **Head);
void adjust_pointers(Node*,Node *);

Main_Head=Head;

if(which_dir==1)
{
temp2=Head->U_R;
Head->U_R=NULL;
temp1=make_node(xchange,ychange,Head->x,Head->y,&Head);
adjust_pointers(temp1,temp2);
}
else if(which_dir==2)
{
temp2=Head->U_L;
Head->U_L=NULL;
temp1=make_node(xchange,ychange,Head->x,Head->y,&Head);
adjust_pointers(temp1,temp2);
}
else if(which_dir==3)
{
temp2=Head->D_R;
Head->D_R=NULL;
temp1=make_node(xchange,ychange,Head->x,Head->y,&Head);
adjust_pointers(temp1,temp2);
}
else if(which_dir==4)
{
temp2=Head->D_L;
Head->D_L=NULL;
temp1=make_node(xchange,ychange,Head->x,Head->y,&Head);
adjust_pointers(temp1,temp2);
}
else if(which_dir==5)
{
temp2=Head->U_R1;
Head->U_R1=NULL;
temp1=make_node(xchange,ychange,Head->x,Head->y,&Head);
adjust_pointers(temp1,temp2);
}
else if(which_dir==6)
{
temp2=Head->U_L1;
Head->U_L1=NULL;
temp1=make_node(xchange,ychange,Head->x,Head->y,&Head);
adjust_pointers(temp1,temp2);
}
else if(which_dir==7)
{
temp2=Head->D_R1;
Head->D_R1=NULL;
temp1=make_node(xchange,ychange,Head->x,Head->y,&Head);
adjust_pointers(temp1,temp2);
}
else if(which_dir==8)
{
temp2=Head->D_L1;
Head->D_L1=NULL;
temp1=make_node(xchange,ychange,Head->x,Head->y,&Head);
adjust_pointers(temp1,temp2);
}

}
//end of function to do the adjustment base on the value of which
direction is not equal


//function to adjust pointers
void adjust_pointers(Node *temp1,Node *temp2)
{
int xint,yint,x,y;
xint=temp1->x;
yint=temp1->y;
x=temp2->x;
y=temp2->y;


        if((xint-x)>=0 && (y-yint)>=0)
        {
        if(temp1->D_L==NULL)
        temp1->D_L=temp2;
        else
        temp1->D_L1=temp2;
        }
        else if((x-xint)>=0 && (y-yint)>=0)
        {
        if(temp1->D_R==NULL)
        temp1->D_R=temp2;
        else
        temp1->D_R1=temp2;
        }
        else if((x-xint)>=0 && (yint-y)>=0)
        {
        if(temp1->U_R==NULL)
        temp1->U_R=temp2;
        else
        temp1->U_R1=temp2;
        }
        else
        {
        if(temp1->U_L==NULL)
        temp1->U_L=temp2;
        else
        temp1->U_L1=temp2;
        }
}

//end of function to adjust the pointers

Node *make_node(int x,int y,int xint,int yint,Node **Head)
{

        getch();

                Node *temp1=new Node();
                temp1->x=x;
                temp1->y=y;

        if((xint-x)>=0 && (y-yint)>=0)
        {

                        line(320+xint,yint,320+x,y);

                        if((*Head)->D_L==NULL)
                               (*Head)->D_L=temp1;
                       else
                               (*Head)->D_L1=temp1;

                        (*Head)=temp1;
        }
        else if((x-xint)>=0 && (y-yint)>=0)
        {

                        line(320+xint,yint,320+x,y);

                        if((*Head)->D_R==NULL)
                               (*Head)->D_R=temp1;
                       else
                               (*Head)->D_R1=temp1;

                       (*Head)=temp1;

        }
        else if((x-xint)>=0 && (yint-y)>=0)
        {

                line(320+xint,yint,320+x,y);

                        if((*Head)->U_R==NULL)
                               (*Head)->U_R=temp1;
                       else
                               (*Head)->U_R1=temp1;
                (*Head)=temp1;

        }
        else
        {
                        line(320+xint,yint,320+x,y);

                        if((*Head)->U_L==NULL)
                               (*Head)->U_L=temp1;
                       else
                               (*Head)->U_L1=temp1;

                        (*Head)=temp1;

        }
        return(temp1);
}



//function to remove redundancy

void remove_red()
{
int i,j;

for(i=51;i<99;i++)
{
        for(j=51;j<99;j++)
        {
                if(getpixel(j,i)!=0)
                {
                putpixel(120+j,120+i,4);
                break;
                }
        }
}


for(i=51;i<99;i++)
{
        for(j=99;j>50;j--)
        {
                if(getpixel(j,i)!=0)
                {
                putpixel(120+j,120+i,4);
                break;
                }
        }
}


//this if for vertical side

for(i=51;i<99;i++)
{
        for(j=51;j<99;j++)
        {
                if(getpixel(i,j)!=0)
                {
                putpixel(120+i,120+j,4);
                break;
                }
        }
}


for(i=51;i<99;i++)
{
        for(j=99;j>50;j--)
        {
                if(getpixel(i,j)!=0)
                {
                putpixel(120+i,120+j,4);
                break;
                }
        }
}



}

//end of function for removing the redundancy



//finding the maximum and minimum of the function
void find_max_min(int &xmin,int &ymin,int &xmax,int &ymax)
{
int count=0;
int c,i,j;

for(i=51;i<=99;i++)
{
for(j=51;j<=99;j++)
{

if((c=getpixel(j,i))!=0)
{
if(count==0)
{
xmin=j;
ymin=i;
xmax=j;
ymax=i;
count=1;
}
else
{
if(xmin>j)
xmin=j;

if(ymax<i)
ymax=i;

if(xmax<j)
xmax=j;
}
}
}
}
}

//end of finding the maximum and minimum of the function


void Drawing_Pencil(int x,int y)
{

union REGS a;
int oldx,oldy;
int p=1;

oldx=x;
oldy=y;
setcolor(5);

while(1)
{

a.x.ax=6;
int86(0x33,&a,&a);
if(a.x.bx==1)
{
line(oldx,oldy,a.x.cx,a.x.dx);
p=0;
break;
}

a.x.ax=5;
int86(0x33,&a,&a);
if(a.x.bx==1)
{
p=1;
oldx=a.x.cx;
oldy=a.x.dx;
}

a.x.ax=3;
int86(0x33,&a,&a);
if((p==1)&&(a.x.cx!=oldx)&&(a.x.dx!=oldy))
{
a.x.ax=2;
int86(0x33,&a,&a);

line(oldx,oldy,a.x.cx,a.x.dx);

a.x.ax=1;
int86(0x33,&a,&a);

oldx=a.x.cx;
oldy=a.x.dx;
}

}
}


float angle(int x,int y,int itr)
{
int i;
int xbac,ybac;
xbac=x;
ybac=y;

for(i=0;i<3;i++)
{
  if(getpixel(xbac,ybac+1)!=0)
  {
  ybac+=1;
  }
  else if(getpixel(xbac-1,ybac+1)!=0)
  {
  xbac-=1;
  ybac+=1;
  }
  else if(getpixel(xbac+1,ybac+1)!=0)
  {
  xbac+=1;
  ybac+=1;
  }
  else if(getpixel(xbac+1,ybac)!=0)
  {
  xbac+=1;
  }
  else if(getpixel(xbac-1,ybac)!=0)
  {
  xbac-=1;
  }
  else
  break;

}

int xfor,yfor;
xfor=x;
yfor=y;

for(i=0;i<3;i++)
{
  if(getpixel(xfor,yfor-1)!=0)
  {
  yfor-=1;
  }
  else if(getpixel(xfor-1,yfor-1)!=0)
  {
  xfor-=1;
  yfor-=1;
  }
  else if(getpixel(xfor+1,yfor-1)!=0)
  {
  xfor+=1;
  yfor-=1;
  }
  else if(getpixel(xfor+1,yfor)!=0)
  {
  xfor+=1;
  }
  else if(getpixel(xfor-1,yfor)!=0)
  {
  xfor-=1;
  }
  else
  break;
}


float theta;

if(((xfor==xbac)&&(yfor==ybac))||yfor==ybac)   //this is found from
testing so don't change
theta=0;
else if(xfor!=xbac)
{
        theta= atan(float(float (yfor)-ybac)/(xfor-xbac));
        theta=(theta*180)/3.142;
}
else
{
theta=90;
}

gotoxy(70,10);
printf("xfor=%d",xfor);
gotoxy(70,11);
printf("xbac=%d",xbac);
gotoxy(70,12);
printf("yfor=%d",yfor);
gotoxy(70,13);
printf("ybac=%d",ybac);


return(theta);
}












"Thomas Guettler" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> Am Tue, 04 Nov 2003 07:48:45 -0800 schrieb RAMESH:
> 
> > hi friends,
> > 
> > It's easy to recognize a handwritten character recognition easily
> > without applying complex theorems at all.
> 
> If it is that easy, please write the code and I will test it.
> 
>  thomas



<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com




Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.




Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.