Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

TRANSFORMÉE DE HOUGH: DÉTECTION DE DROITES




Description

Cliquez pour voir la capture en taille normale
Ce programme permet de mieux comprendre le fonctionnement de la transformée de Hough.
Cette transformée permet de  changer d'espace de représentation. Un point dans l'espace (X,Y) sera transformée en sinusoïde dans l'espace (R,Theta) et inversement un point dans le plan (R, Theta) sera une droite dans le plan (X,Y).

Ce qui est intéressant, c'est que la succession de point formant une droite dans le plan (X,Y) formera des sinusoïdes qui seront concurrente en un point.

Cette transformé permet donc de détecter les droites dans une image.
 

Source

  • //*****************************************************************************************
  • //Author MORARD Vincent
  • //Date : 28/06/07
  • //Contact: vincent.morard@cpe.fr
  • //WebSite: pistol.petesampras.free.fr
  • //*****************************************************************************************
  • //Includes----------------------------------------------------------------------------------
  • #include "windows.h"
  • #include "cmugraphics.h"
  • #include "math.h"
  • #include <vector>
  • using namespace std;
  • //Define------------------------------------------------------------------------------------
  • #define SPACE_X1 100
  • #define SPACE_Y1 10
  • #define SPACE_X2 300
  • #define SPACE_Y2 210
  • #define SPACE_CENTER_X 200
  • #define SPACE_CENTER_Y 110
  • #define HOUGH_X1 50
  • #define HOUGH_Y1 230
  • #define HOUGH_X2 350
  • #define HOUGH_Y2 510
  • #define HOUGH_CENTER_X 50
  • #define HOUGH_CENTER_Y 370
  • const double Pi = 3.141592653589793238462643383279;
  • //Struct---------------------------------------------------------------------------------
  • struct Transform
  • {
  • double X,Y,Theta,R;
  • bool Inv_Transform;
  • };
  • //Header's function-----------------------------------------------------------------------
  • void DrawAxis(window &F,int Graph=-1);
  • void DrawCosinus(window &F,double R,double Theta);
  • void DrawLine(window &F,double X,double Y,double Theta);
  • void UpdateHough(window &F,vector<Transform> Vect);
  • void UpdateSpace(window &F,vector<Transform> Vect);
  • void ButtonDownAction(window &F,vector<Transform> *Vect,int MouseX,int MouseY,bool Final=0);
  • void UpdateCoord(window &F,vector<Transform> *Vect);
  • void DrawInterface(window &F,bool *Reset,bool *Exit,bool *Click);
  • //*******************************************************************************************
  • int APIENTRY WinMain(HINSTANCE hInstance,
  • HINSTANCE hPrevInstance,
  • LPSTR lpCmdLine,
  • int nCmdShow)
  • {
  • bool Exit=false;
  • bool Reset=true;
  • bool Click=false;
  • int Cpt=0;
  • window F(390,600,0,0); //create a 390 width and 600 Height window
  • //at the position (0,0)
  • F.SetWaitClose(false); //Close the window when we exit
  • F.SetBuffering(true); //Allow double buffering
  • F.ChangeTitle("Hough tranform");//Change title
  • vector<Transform>Vect; //Vector to stock all the parameters
  • Vect.resize(0); //init vector
  • do
  • {
  • if(++Cpt==100)
  • {
  • MSG msg;
  • if(!GetMessage(&msg, NULL, 0, 0))//On recoit le message de fin =>on a appuyé sur la croix
  • exit(1);
  • Cpt=0;
  • }
  • if(Reset) //if Reset : we redraw axis
  • {
  • Reset=false;
  • DrawAxis(F);
  • Vect.resize(0); //And we resize to 0 the vector
  • }
  • UpdateCoord(F,&Vect); //To update the points and theres transforms
  • DrawInterface(F,&Reset,&Exit,&Click); //Button
  • F.UpdateBuffer();
  • Sleep(20); //The process gives back the hand to an another process
  • //during 20 ms
  • }
  • while(!Exit);
  • exit(0);
  • return 0;
  • }
  • //This function checks the mouse's event and calls the appropriate function
  • void UpdateCoord(window &F,vector<Transform>*Vect)
  • {
  • int MouseX,MouseY;
  • bool Click=false;
  • F.GetMouseCoord(MouseX,MouseY);
  • if(MouseY>540)
  • return;
  • //If the user clicks on the screen, he will see the result of Hough tranform in real time
  • while(F.GetButtonState(LEFT_BUTTON,MouseX,MouseY)==BUTTON_DOWN)
  • {
  • ButtonDownAction(F,Vect,MouseX,MouseY); //temporary action
  • F.UpdateBuffer();
  • Sleep(30);
  • Click=true;
  • }
  • if(Click) //if we click the result keeps on the sreen
  • ButtonDownAction(F,Vect,MouseX,MouseY,1);
  • }
  • //This function takes back the coord of the mouse in the graph
  • //and calls the function to make a transformation into Hough's space.
  • void ButtonDownAction(window &F,vector<Transform> *Vect,int MouseX,int MouseY,bool Final)
  • {
  • Transform Hough; //this structure allow us to stock all the parameters of the Hough's transform
  • //X and Y , R and theta
  • //if the mouse is over the graph 1
  • if(MouseX > SPACE_X1 && MouseX < SPACE_X2 && MouseY > SPACE_Y1 && MouseY < SPACE_Y2)
  • {
  • //We just have to tranform MouseX and MouseY to have the coord of the position of
  • //the mouse on the graph
  • Hough.X = MouseX-SPACE_CENTER_X;
  • Hough.Y = SPACE_CENTER_Y-MouseY;
  • //With X and Y we are able to get R and Theta in polar coord
  • //R=sqrt(X² + Y²)
  • //tan(Theta) = Y/X
  • Hough.R = sqrt((double)(Hough.X*Hough.X+Hough.Y*Hough.Y));
  • Hough.Theta = atan((double)Hough.Y/Hough.X)+Pi/2;
  • if(Hough.X>0)
  • Hough.Theta+=Pi;
  • Hough.Inv_Transform = 0; //Hough transform
  • Vect->push_back(Hough); //we push the new point
  • UpdateHough(F,*Vect); //and we update the transform
  • if(!Final)
  • Vect->pop_back(); //if we still click, we pop the new point
  • else
  • {
  • F.SetPen(RED); //if we stop clicking, we draw a circle on the screen
  • F.SetBrush(RED);
  • F.DrawCircle(MouseX,MouseY,3,FRAME);
  • }
  • }
  • else if(MouseX >= HOUGH_X1 && MouseX < HOUGH_X2 && MouseY > HOUGH_Y1 && MouseY < HOUGH_Y2)
  • {
  • double Pas=Pi/(HOUGH_X2-HOUGH_X1);
  • //We have got easily R and Theta
  • Hough.Theta = (MouseX-HOUGH_CENTER_X)*Pas;
  • Hough.R = HOUGH_CENTER_Y-MouseY;
  • //And we convert R and Theta in cartesien coord
  • Hough.Y = Hough.R*cos(Hough.Theta);
  • Hough.X = -Hough.R*sin(Hough.Theta);
  • Hough.Inv_Transform = 1; //Hough reverse
  • Vect->push_back(Hough);
  • UpdateSpace(F,*Vect);
  • if(!Final)
  • Vect->pop_back();
  • else
  • {
  • F.SetBrush(GREEN);
  • F.SetPen(GREEN);
  • F.DrawCircle(MouseX,MouseY,3,FILLED);
  • }
  • }
  • }
  • void UpdateHough(window &F,vector<Transform> Vect)
  • {
  • DrawAxis(F,2);
  • F.SetPen(GREEN);
  • F.SetBrush(GREEN);
  • int Size=Vect.size();
  • for(int i=0;i<Size;i++)
  • {
  • if(! Vect[i].Inv_Transform )
  • DrawCosinus(F,Vect[i].R,Vect[i].Theta);
  • else
  • F.DrawCircle(Vect[i].Theta*(HOUGH_X2-HOUGH_X1)/Pi+HOUGH_CENTER_X,HOUGH_CENTER_Y-Vect[i].R,3);
  • }
  • }
  • void UpdateSpace(window &F,vector<Transform> Vect)
  • {
  • DrawAxis(F,1);
  • F.SetPen(RED);
  • F.SetBrush(RED);
  • int Size=Vect.size();
  • for(int i=0;i<Size;i++)
  • if(Vect[i].Inv_Transform )
  • DrawLine(F,Vect[i].X,Vect[i].Y,Vect[i].Theta);
  • else
  • F.DrawCircle(Vect[i].X+SPACE_CENTER_X,SPACE_CENTER_Y-Vect[i].Y,3);
  • }
  • void DrawCosinus(window &F,double R,double Theta)
  • {
  • int Width=HOUGH_X2-HOUGH_X1;
  • int Height=HOUGH_Y2-HOUGH_Y1;
  • double x,y;
  • double Pas=Pi/Width;
  • F.SetPen(GREEN);
  • F.SetBrush(GREEN);
  • //for each pixel of the graph, we evaluate the y coord with cosinus
  • for(double i=HOUGH_X1;i<HOUGH_X2;i++)
  • {
  • x=i-HOUGH_CENTER_X;
  • x*=Pas; //conversion into radian
  • y=R*cos(x-Theta);
  • F.DrawPixel(i,HOUGH_CENTER_Y-y);
  • }
  • }
  • //This function is able to draw a line with one point and one angle
  • void DrawLine(window &F,double X,double Y,double Theta)
  • {
  • //Vecteur is the direction
  • double Vecteur=tan(Theta);
  • X+=SPACE_CENTER_X;
  • Y=SPACE_CENTER_Y-Y;
  • if(X>SPACE_X2 || X<SPACE_X1 || Y>SPACE_Y2 || Y<SPACE_Y1)
  • return;
  • int LastX=X;
  • int LastY=Y;
  • double i,j;
  • F.SetPen(RED);
  • F.SetBrush(RED);
  • for(i=X;i<=SPACE_X2;i+=0.5)
  • {
  • if((j=Y-Vecteur*(i-X))>SPACE_Y2 || j<SPACE_Y1)
  • break;
  • LastX=i; //We get the coord of the point whith cut the graph's window
  • LastY=j;
  • }
  • F.DrawLine((int)X,(int)Y,LastX,LastY);
  • LastX=X;
  • LastY=Y;
  • //We do the same thing in the other way
  • for(i=X;i>=SPACE_X1;i-=0.5)
  • {
  • if((j=j=Y-Vecteur*(i-X))>SPACE_Y2 || j<SPACE_Y1)
  • break;
  • LastX=i;
  • LastY=j;
  • }
  • F.DrawLine((int)X,(int)Y,LastX,LastY);
  • }
  • void DrawInterface(window &F,bool *Reset,bool *Exit,bool *Click)
  • {
  • int MouseX,MouseY;
  • F.SetFont(20,BOLD,SWISS);
  • F.SetPen(WHITE);
  • F.SetBrush(WHITE);
  • F.DrawRectangle(100,540,400,590);
  • F.SetPen(NAVYBLUE,2);
  • //F.DrawRectangle(210,545,270,575);
  • F.DrawString(110,550,"Reset");
  • F.DrawString(220,550,"Quit");
  • if(F.GetButtonState(LEFT_BUTTON,MouseX,MouseY)==BUTTON_DOWN)
  • {
  • if(MouseX>=80 && MouseX<180 && MouseY>545 && MouseY<575)
  • *Click=true;
  • if(MouseX>=210 && MouseX<270 && MouseY>545 && MouseY<575)
  • *Click=true;
  • }
  • else if (*Click)
  • {
  • *Click=false;
  • if(MouseX>=80 && MouseX<180 && MouseY>545 && MouseY<575)
  • *Reset=true;
  • if(MouseX>=210 && MouseX<270 && MouseY>545 && MouseY<575)
  • *Exit=true;
  • }
  • else
  • *Click=false;
  • }
  • void DrawAxis(window &F,int Graph)
  • {
  • F.SetBrush(WHITE);
  • F.SetFont(15,BOLD,SWISS);
  • if(Graph!=2) //We do not draw again graph 2
  • {
  • F.SetPen(DARKRED,3);
  • F.DrawRectangle(SPACE_X1,SPACE_Y1,SPACE_X2,SPACE_Y2);
  • F.SetPen(BLACK);
  • //y-axis
  • F.DrawLine(SPACE_CENTER_X,SPACE_Y1,SPACE_CENTER_X,SPACE_Y2);
  • //x-axis
  • F.DrawLine(SPACE_X1,SPACE_CENTER_Y,SPACE_X2,SPACE_CENTER_Y);
  • //Arrows
  • F.DrawLine(SPACE_CENTER_X-5,SPACE_Y1+9,SPACE_CENTER_X,SPACE_Y1);
  • F.DrawLine(SPACE_CENTER_X+5,SPACE_Y1+9,SPACE_CENTER_X,SPACE_Y1);
  • F.DrawLine(SPACE_X2-5,SPACE_CENTER_Y+3,SPACE_X2,SPACE_CENTER_Y);
  • F.DrawLine(SPACE_X2-5,SPACE_CENTER_Y-3,SPACE_X2,SPACE_CENTER_Y);
  • //Legende
  • F.DrawString(SPACE_CENTER_X,SPACE_Y1-16,"y");
  • F.DrawString(SPACE_X2+10,SPACE_CENTER_Y,"x");
  • }
  • if(Graph!=1) //We do not draw again graph 1
  • {
  • F.SetPen(DARKGREEN,3);
  • F.DrawRectangle(HOUGH_X1,HOUGH_Y1,HOUGH_X2,HOUGH_Y2);
  • F.SetPen(BLACK);
  • //y-axis
  • F.DrawLine(HOUGH_CENTER_X,HOUGH_Y1,HOUGH_CENTER_X,HOUGH_Y2);
  • //x-axis
  • F.DrawLine(HOUGH_X1,HOUGH_CENTER_Y,HOUGH_X2,HOUGH_CENTER_Y);
  • //Arrows
  • F.DrawLine(HOUGH_CENTER_X-5,HOUGH_Y1+9,HOUGH_CENTER_X,HOUGH_Y1);
  • F.DrawLine(HOUGH_CENTER_X+5,HOUGH_Y1+9,HOUGH_CENTER_X,HOUGH_Y1);
  • F.DrawLine(HOUGH_X2-5,HOUGH_CENTER_Y+3,HOUGH_X2,HOUGH_CENTER_Y);
  • F.DrawLine(HOUGH_X2-5,HOUGH_CENTER_Y-3,HOUGH_X2,HOUGH_CENTER_Y);
  • //Legende
  • F.DrawString(HOUGH_CENTER_X,HOUGH_Y1-16,"Theta");
  • F.DrawString(HOUGH_X2+8,HOUGH_CENTER_Y,"R");
  • }
  • }
//*****************************************************************************************
//Author	MORARD Vincent 
//Date :	28/06/07 
//Contact:	vincent.morard@cpe.fr	
//WebSite:	pistol.petesampras.free.fr
//*****************************************************************************************

//Includes----------------------------------------------------------------------------------
#include "windows.h"
#include "cmugraphics.h"
#include "math.h"
#include <vector>
using namespace std;

//Define------------------------------------------------------------------------------------
#define SPACE_X1 100
#define SPACE_Y1 10
#define SPACE_X2 300
#define SPACE_Y2 210

#define SPACE_CENTER_X 200
#define SPACE_CENTER_Y 110

#define HOUGH_X1 50
#define HOUGH_Y1 230
#define HOUGH_X2 350
#define HOUGH_Y2 510

#define HOUGH_CENTER_X 50
#define HOUGH_CENTER_Y 370
const double Pi = 3.141592653589793238462643383279;

//Struct---------------------------------------------------------------------------------
struct Transform
{
	double X,Y,Theta,R;
	bool Inv_Transform;
};


//Header's function-----------------------------------------------------------------------
void DrawAxis(window &F,int Graph=-1);
void DrawCosinus(window &F,double R,double Theta);
void DrawLine(window &F,double X,double Y,double Theta);
void UpdateHough(window &F,vector<Transform> Vect);
void UpdateSpace(window &F,vector<Transform> Vect);
void ButtonDownAction(window &F,vector<Transform> *Vect,int MouseX,int MouseY,bool Final=0);
void UpdateCoord(window &F,vector<Transform> *Vect);
void DrawInterface(window &F,bool *Reset,bool *Exit,bool *Click);


//*******************************************************************************************

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)

{
	bool Exit=false;
	bool Reset=true;
	bool Click=false;
	int Cpt=0;
	window F(390,600,0,0);			//create a 390 width and 600 Height window 
									//at the position (0,0)
	F.SetWaitClose(false);			//Close the window when we exit
	F.SetBuffering(true);			//Allow double buffering
	F.ChangeTitle("Hough tranform");//Change title
	
	vector<Transform>Vect;			//Vector to stock all the parameters
	Vect.resize(0);					//init vector


	do
	{
		if(++Cpt==100)
		{
			MSG msg;
			if(!GetMessage(&msg, NULL, 0, 0))//On recoit le message de fin =>on a appuyé sur la croix
				exit(1);
			Cpt=0;
		}
		if(Reset)					//if Reset : we redraw axis
		{	
			Reset=false;
			DrawAxis(F);
			Vect.resize(0);			//And we resize to 0 the vector
		}
		UpdateCoord(F,&Vect);		//To update the points and theres transforms
		DrawInterface(F,&Reset,&Exit,&Click);		//Button
		F.UpdateBuffer();			
		Sleep(20);					//The process gives back the hand to an another process
									//during 20 ms
	}
	while(!Exit);
	exit(0);
	return 0;
}

//This function checks the mouse's event and calls the appropriate function
void UpdateCoord(window &F,vector<Transform>*Vect)
{
	int MouseX,MouseY;
	bool Click=false;
	
	F.GetMouseCoord(MouseX,MouseY);
	if(MouseY>540)
		return;
	//If the user clicks on the screen, he will see the result of Hough tranform in real time
	while(F.GetButtonState(LEFT_BUTTON,MouseX,MouseY)==BUTTON_DOWN)
	{	
		
		ButtonDownAction(F,Vect,MouseX,MouseY);		//temporary action
		F.UpdateBuffer();
	
		Sleep(30);
		Click=true;
	}
	if(Click)											//if we click the result keeps on the sreen
		ButtonDownAction(F,Vect,MouseX,MouseY,1);		
}


//This function takes back the coord of the mouse in the graph
//and calls the function to make a transformation into Hough's space.
void ButtonDownAction(window &F,vector<Transform> *Vect,int MouseX,int MouseY,bool Final)
{
	Transform Hough;		//this structure allow us to stock all the parameters of the Hough's transform
							//X and Y , R and theta

	//if the mouse is over the graph 1
	if(MouseX > SPACE_X1 && MouseX < SPACE_X2 && MouseY > SPACE_Y1 && MouseY < SPACE_Y2)
	{
		//We just have to tranform MouseX and MouseY to have the coord of the position of
		//the mouse on the graph
		Hough.X = MouseX-SPACE_CENTER_X;
		Hough.Y = SPACE_CENTER_Y-MouseY;
		//With X and Y we are able to get R and Theta in polar coord
		//R=sqrt(X² + Y²)
		//tan(Theta) = Y/X
		Hough.R = sqrt((double)(Hough.X*Hough.X+Hough.Y*Hough.Y));
		Hough.Theta = atan((double)Hough.Y/Hough.X)+Pi/2;
		if(Hough.X>0)
			Hough.Theta+=Pi;
		Hough.Inv_Transform = 0;		//Hough transform

		Vect->push_back(Hough);			//we push the new point
		UpdateHough(F,*Vect);			//and we update the transform
		if(!Final)
			Vect->pop_back();			//if we still click, we pop the new point
		else
		{
			F.SetPen(RED);				//if we stop clicking, we draw a circle on the screen
			F.SetBrush(RED);
			F.DrawCircle(MouseX,MouseY,3,FRAME);
	
		}
			

	}
	else if(MouseX >= HOUGH_X1 && MouseX < HOUGH_X2 && MouseY > HOUGH_Y1 && MouseY < HOUGH_Y2)
	{
		double Pas=Pi/(HOUGH_X2-HOUGH_X1);
		//We have got easily R and Theta 
		Hough.Theta = (MouseX-HOUGH_CENTER_X)*Pas;
		Hough.R = HOUGH_CENTER_Y-MouseY;
		//And we convert R and Theta in cartesien coord
		Hough.Y = Hough.R*cos(Hough.Theta);
		Hough.X = -Hough.R*sin(Hough.Theta);
		Hough.Inv_Transform = 1;		//Hough reverse

		Vect->push_back(Hough);
		UpdateSpace(F,*Vect);
		if(!Final)
			Vect->pop_back();
		else
		{
			F.SetBrush(GREEN);
			F.SetPen(GREEN);	
			F.DrawCircle(MouseX,MouseY,3,FILLED);
		}	
	}
}

void UpdateHough(window &F,vector<Transform> Vect)
{
	
	DrawAxis(F,2);
	F.SetPen(GREEN);
	F.SetBrush(GREEN);
	int Size=Vect.size();
	for(int i=0;i<Size;i++)
	{
		if(! Vect[i].Inv_Transform )
			DrawCosinus(F,Vect[i].R,Vect[i].Theta);
		else
			F.DrawCircle(Vect[i].Theta*(HOUGH_X2-HOUGH_X1)/Pi+HOUGH_CENTER_X,HOUGH_CENTER_Y-Vect[i].R,3);
			
	}
		
}
void UpdateSpace(window &F,vector<Transform> Vect)
{
	
	DrawAxis(F,1);
	F.SetPen(RED);
	F.SetBrush(RED);
	int Size=Vect.size();
	for(int i=0;i<Size;i++)
		if(Vect[i].Inv_Transform )
			DrawLine(F,Vect[i].X,Vect[i].Y,Vect[i].Theta);
		else
			F.DrawCircle(Vect[i].X+SPACE_CENTER_X,SPACE_CENTER_Y-Vect[i].Y,3);
			

}

void DrawCosinus(window &F,double R,double Theta)
{
	int Width=HOUGH_X2-HOUGH_X1;
	int Height=HOUGH_Y2-HOUGH_Y1;
	double x,y;
	double Pas=Pi/Width;		
	F.SetPen(GREEN);
	F.SetBrush(GREEN);
	//for each pixel of the graph, we evaluate the y coord with cosinus
	for(double i=HOUGH_X1;i<HOUGH_X2;i++)
	{
		x=i-HOUGH_CENTER_X;
		x*=Pas;					//conversion into radian
		y=R*cos(x-Theta);	
		F.DrawPixel(i,HOUGH_CENTER_Y-y);
	}		
}


//This function is able to draw a line with one point and one angle
void DrawLine(window &F,double X,double Y,double Theta)
{
	//Vecteur is the direction
	double Vecteur=tan(Theta);	

	X+=SPACE_CENTER_X;
	Y=SPACE_CENTER_Y-Y;
	if(X>SPACE_X2 || X<SPACE_X1 || Y>SPACE_Y2 || Y<SPACE_Y1)
		return;

	int LastX=X;
	int LastY=Y;
	double  i,j;
	
	F.SetPen(RED);
	F.SetBrush(RED);
	for(i=X;i<=SPACE_X2;i+=0.5)
	{
		if((j=Y-Vecteur*(i-X))>SPACE_Y2 || j<SPACE_Y1)
			break;
		
		LastX=i;				//We get the coord of the point whith cut the graph's window
		LastY=j;
	}
	F.DrawLine((int)X,(int)Y,LastX,LastY);
	LastX=X;
	LastY=Y;

	//We do the same thing in the other way
	for(i=X;i>=SPACE_X1;i-=0.5)
	{
		if((j=j=Y-Vecteur*(i-X))>SPACE_Y2 || j<SPACE_Y1)
			break;
		
		LastX=i;
		LastY=j;
	}
	F.DrawLine((int)X,(int)Y,LastX,LastY);


}


void DrawInterface(window &F,bool *Reset,bool *Exit,bool *Click)
{
	int MouseX,MouseY;
	F.SetFont(20,BOLD,SWISS);
	F.SetPen(WHITE);
	F.SetBrush(WHITE);
	F.DrawRectangle(100,540,400,590);


	F.SetPen(NAVYBLUE,2);
	//F.DrawRectangle(210,545,270,575);
	F.DrawString(110,550,"Reset");
	F.DrawString(220,550,"Quit");

	if(F.GetButtonState(LEFT_BUTTON,MouseX,MouseY)==BUTTON_DOWN)
	{
		if(MouseX>=80 && MouseX<180 && MouseY>545 && MouseY<575)
			*Click=true;
		if(MouseX>=210 && MouseX<270 && MouseY>545 && MouseY<575)
			*Click=true;
	}
	else if (*Click)
	{
		*Click=false;
		if(MouseX>=80 && MouseX<180 && MouseY>545 && MouseY<575)
			*Reset=true;
		if(MouseX>=210 && MouseX<270 && MouseY>545 && MouseY<575)
			*Exit=true;


	}
	else
		*Click=false;

}

void DrawAxis(window &F,int Graph)
{
	
	F.SetBrush(WHITE);
	F.SetFont(15,BOLD,SWISS);
	if(Graph!=2)			//We do not draw again graph 2
	{
		F.SetPen(DARKRED,3);
		F.DrawRectangle(SPACE_X1,SPACE_Y1,SPACE_X2,SPACE_Y2);
		F.SetPen(BLACK);
		//y-axis
		F.DrawLine(SPACE_CENTER_X,SPACE_Y1,SPACE_CENTER_X,SPACE_Y2);
		//x-axis
		F.DrawLine(SPACE_X1,SPACE_CENTER_Y,SPACE_X2,SPACE_CENTER_Y);
		//Arrows
		F.DrawLine(SPACE_CENTER_X-5,SPACE_Y1+9,SPACE_CENTER_X,SPACE_Y1);
		F.DrawLine(SPACE_CENTER_X+5,SPACE_Y1+9,SPACE_CENTER_X,SPACE_Y1);
		F.DrawLine(SPACE_X2-5,SPACE_CENTER_Y+3,SPACE_X2,SPACE_CENTER_Y);
		F.DrawLine(SPACE_X2-5,SPACE_CENTER_Y-3,SPACE_X2,SPACE_CENTER_Y);
		//Legende
		F.DrawString(SPACE_CENTER_X,SPACE_Y1-16,"y");
		F.DrawString(SPACE_X2+10,SPACE_CENTER_Y,"x");
	}
	if(Graph!=1)			//We do not draw again graph 1
	{
		F.SetPen(DARKGREEN,3);
		F.DrawRectangle(HOUGH_X1,HOUGH_Y1,HOUGH_X2,HOUGH_Y2);
		F.SetPen(BLACK);
		//y-axis
		F.DrawLine(HOUGH_CENTER_X,HOUGH_Y1,HOUGH_CENTER_X,HOUGH_Y2);
		//x-axis
		F.DrawLine(HOUGH_X1,HOUGH_CENTER_Y,HOUGH_X2,HOUGH_CENTER_Y);
		//Arrows
		F.DrawLine(HOUGH_CENTER_X-5,HOUGH_Y1+9,HOUGH_CENTER_X,HOUGH_Y1);
		F.DrawLine(HOUGH_CENTER_X+5,HOUGH_Y1+9,HOUGH_CENTER_X,HOUGH_Y1);
		F.DrawLine(HOUGH_X2-5,HOUGH_CENTER_Y+3,HOUGH_X2,HOUGH_CENTER_Y);
		F.DrawLine(HOUGH_X2-5,HOUGH_CENTER_Y-3,HOUGH_X2,HOUGH_CENTER_Y);
		//Legende
		F.DrawString(HOUGH_CENTER_X,HOUGH_Y1-16,"Theta");
		F.DrawString(HOUGH_X2+8,HOUGH_CENTER_Y,"R");
	}
	
}

Fichier Zip

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

Commentaires et avis

signaler à un administrateur
Commentaire de Kirua le 10/07/2007 21:49:53

Je comprends bien l'idée de la concurrence des sinusoïdes associées à des points alignés, mais pourquoi n'est-il pas aussi efficace de tester l'alignement des points dans l'espace (X,Y) directement? Ca m'intrigue ^^.

signaler à un administrateur
Commentaire de Pistol_Pete le 11/07/2007 08:25:27

Salut Kirua

Je comprends très bien ta question puisqu’en effet il serait, dans ce cas là, beaucoup plus rapide de calculer l’alignement des points dans le domaine (X, Y)
Je suis entrain de programmer un nouveau petit programme qui permet de calculer la transformée de Hough sur une vraie image. En fait sur le gradient de l’image. Ici on voit tout l’intérêt d’un tel procéder. On pourra donc dégager les droites qui ressortent le plus dans l’image

C’est très intéressant comme procédé car on part dans le sens inverse :
Il y a des algorithmes qui, pour identifier ces formes élémentaires, entreprennent de suivre les contours pour finalement les lier par des critères plus ou moins complexes afin de remonter jusqu'aux formes recherchées. Une autre approche de ce problème serait de tenter d'accumuler des évidences sur l'existence d'une forme particulière telle qu'une droite, un cercle ou  une ellipse. C'est cette démarche qui a été adoptée dans la transformée de Hough.

signaler à un administrateur
Commentaire de hentati1 le 31/01/2008 15:29:28

Je travaille avec visual C et je debute dans le traitement d'image et en programmation C. Je dois effectuer la detection de cercles dans une image avec la transformee de Hough. Je cherche un debut de code qui puisse me mettre sur la piste car je ne sais pas du tout comment commencer.

Pouvez-vous m'aider svp? Merci

signaler à un administrateur
Commentaire de Pistol_Pete le 31/01/2008 15:48:42

Salut Hentati

Ben déja commence a bien te documenter sur la transformée de Hough. Il y a plein d'articles qui décrivent tres bien la méthode.
Une fois le principe bien connue et maitrisé, il faut que tu ecrives A LA MAIN l'algorithme de ton programme.
Apres il ne reste pas qu'a traduire ce que tu as ecrit sur le papier en C ou en C++. Si tu connais bien ce langage, c'est la partie la plus rapide. Bien sur  ce n'est le cas que si tu as bien préparé le chemin avant.

A+

signaler à un administrateur
Commentaire de psyjc le 18/04/2008 10:58:53

Manque cmugraphics.h dans l'archive :/

signaler à un administrateur
Commentaire de Pistol_Pete le 18/04/2008 15:34:39

Salut
Cmugraphics est une lib que tu peut trouver sur mon site internet.

A+

signaler à un administrateur
Commentaire de fou08 le 20/05/2008 17:31:20

salut,
j'ai réalisé un programme en C pour la détection des droites dans une image donnée. le problème j'ai remplie l'accummulateur, j'ai cherché le max mais je n'arrive pas a affoché les droites existent

signaler à un administrateur
Commentaire de Pistol_Pete le 20/05/2008 21:27:55

Salut

Comment veux tu que je t'aide?
Regarde la fonction DrawLine où comment dessiner une droite à partir de son origine et d'un angle.

A+

signaler à un administrateur
Commentaire de fou08 le 21/05/2008 10:31:25

bonjour,
lorsque je trouve le max dans l'accumulateur, donc j'ai détecté une valeur de rhou, et une valeur de theta
à partir de cette étape, comment je peut déssiner la droite?

signaler à un administrateur
Commentaire de olibara le 13/09/2008 21:46:43

Bonjour

Je profite de ce thread et de la compétence de ses interlocuteur pour poser une bete question !

Je viens de constater que si on faisait un Drawline avec un trait un peu épais, les angles de flechisement n'etaient pas dessinés c'est donc comme si j'avais dessiné une suite de rectangles ayant pour mediane les lignes

J'ai cru que le DrawPath allait résoudre le problème mais c'est la meme chose

Existe-il une solution a ce probleme sans devoir ecrire une nouvelle fonction drawline ?


Merci pour vos suggestions

signaler à un administrateur
Commentaire de Pistol_Pete le 22/09/2008 16:01:31

Salut
Je ne suis pas complétement certain d'avoir compris ton problème. Si je résume: lorsque tu dessines une droite avec un pinceau épais, il dessine une succession de rectangle qui forme au final une ligne?
Pour ma part je n'ai jamais rencontré ce probleme avec la fonction DrawLine. Pourrais tu m'envoyer une image du resultat, c'est souvent plus parlant qu'un long discours.
A+

signaler à un administrateur
Commentaire de fikriieea le 28/12/2008 01:03:24

moi je cherche " recherche sur transformée de Hough"

signaler à un administrateur
Commentaire de olibara le 28/12/2008 09:33:24

Salut Pistom Pete

Vu la difficulté d'associer des images et des fichier dans le Forum Code-Source (ce qui est tres dommage), je te propose d'aller voir l'image et meme un projet minimum reproduisant cet effet sur le lien ci-dessous.

Actuelleent, je n'ai pas trouvé de solution objective.

Je pense in fine qu'un Graphics devrait disposer de quelque proprieté supplémentaires en relation avec son transformmatrix
- 1 - Activer desactiver l'usage implicite du transformatrix
- 2 - Desactiver l'usage du transformmatrix sur l'epaisseur des pen

http://www.developpez.net/forums/d637442/dotnet/csharp/graphics-drawline-resultat-bizare/#post3822697

signaler à un administrateur
Commentaire de janouta le 12/04/2009 23:34:49

Bonjour,
Pourquoi lorsque je compile le code , j'ai toujours de variables (image , window ) non défini? et pourtant l'exécutable marche ! je débute dans le traitement d'image ainsi qu'avec le C donc peut être ça va vous paraitre bête comme question , mais j'espère que vous m'aidiez à comprendre ce code parce que j'en ai vraiment besoin. pleaaasee
Merci d'avance
Cordialement

signaler à un administrateur
Commentaire de Pistol_Pete le 14/04/2009 08:28:52

Si l'exécutable est généré pas de soucis donc.
A+

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

Transformée de Hough [ par elo29 ] Bonjour, Je travaille avec visual C++ et je debute dans le traitement d'image et en programmation C++. Je dois effectuer la detection de cercles dans Transformée de Hough ... Help me :( [ par ouafaa ] Bonjour a tout le mondedans le cadre d'un projet, je suis ramenée à detecter une elipse dans une Transformée Inverse de Hough [ par s1a1j2 ] Bonjour Tout le monde,Je cherche la transformée de Hough directe et surtout la transformée inverse Hough. J'espère trouver un code simple en Langage C détection de route dans une image de rue [ par wnxbcvqmsldkfjgh ] Bonjour,J'ai un projet dans lequel je dois détecter une route dans une image de rue, contenant bâtiments, piétons, voitures... Savez-vous si on peut t Mise en couleur d'image sur une page HTML [ par stephane85700 ] bonjour, Je débute dans la création de site, et j'aimerai un peu de vos lumières pour avancer.Je souhaiterais pouvoir créer une page ou il serait poss traitement d'image [ par salma2011 ] Slt tt le monde,je cherche un théme pour ma representation de PFE avec powerpoint,j'ai comme sujet le traitement d'image avec vc++,,qq1 peut m'aider?? Resize image [Urgent !] [ par The Red Man ] Bonjour,Est-ce que vous avez une idée de l'algo (enfin le code :D) en C qui donnerait la possibilité de réduire ou agrandir une image !Merci ! Technologie et type de format renvoyé par une webcam [ par Evanok ] Bonjour, Je dois réaliser un projet me permettant de mouvoir le curseur de ma souris grace a un mouvement détecté devant ma webcam. Je suis en train d creation d'un tableau et fonction image [ par zaz0u ] Alors voila je voudrai faire un tableau qui permet d'afficher des images avec la lib SDL!je sais faire un tableau et je sais afficher une image mais m fichier image (bmp, jpg) à convertir en fichier txt [ par develdelphi ] Bonjour,Je cherche un code pouvant représenter un fichier image N/B en fichier texte. C'est un sujet sur les traitements d'images assez difficile je r


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,421 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.