Code: Select all

```
void Projeto1Frm::Hough(wxImage& image)
{
double pi = 3.14159265358979323846;
int numAngleCells = 360/2;
double rho = 0;
int dx = image.GetWidth();
int dy = image.GetHeight();
int x = 0;
int y = 0;
double rhoMax2 = sqrt(dx^2+dy^2);
wxString rhoMax3 = wxString::Format(wxT("%f"), rhoMax2);
int rhoMax = wxAtoi(rhoMax3);
int theta = 0;
double rhoArray[dx][dy];
int thetaArray[dx][dy];
int count = 0;
int xArray[rhoMax];
int yArray[rhoMax];
unsigned char *data = image.GetData();
wxFFile file(wxT("rho.txt"),"w");
wxString buffer;
wxFFile file2(wxT("theta.txt"),"w");
wxString buffer2;
wxFFile file3(wxT("pic.txt"),"w");
wxString buffer3;
wxFFile file4(wxT("points.txt"),"w");
wxString buffer4;
wxFFile file5(wxT("points2.txt"),"w");
wxString buffer5;
//Hough Accumulator
// For all rows in image.
for (y=0; y<dy-1; y++)
{
// For all pixel in one row.
for (x=0; x<dx-1; x++)
{
// Is there a point there or not. If not, just skip the pixel.
long pos = (y * dx + x) * 3;
if (data[pos]>0)
{
for (theta=0; theta<numAngleCells-1;theta++)
{
rho = rhoMax + x*cos(theta*pi/numAngleCells) + y*sin(theta*pi/numAngleCells);
// Ignore negative values...
// Plot the finding (theta,r) into an array...
if (rho>0)
{
xArray[count]=x;
yArray[count]=y;
if (xArray[count]!=xArray[count-1])
{
buffer4.Printf("%d.%d ",xArray[count],yArray[count]);
file4.Write(buffer4);
}
rhoArray[x][y]=rho;
thetaArray[x][y]=theta;
buffer.Printf("%f,%d,%d,%d ",rho,theta,x,y);
file.Write(buffer);
buffer2.Printf("%d ",theta);
file2.Write(buffer2);
buffer3.Printf("%d ",data[pos]);
file3.Write(buffer3);
count++;
}
}
}
}
}
//print??? What's the problem with xArray???
for(int i=1; i < rhoMax; i++)
{
buffer5.Printf("%d ",xArray[i]);
file5.Write(buffer5);
}
}
```