problem with arrays in Hough Transform Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
cavernah
In need of some credit
In need of some credit
Posts: 6
Joined: Mon Jan 19, 2009 3:32 am
Location: Brazil

problem with arrays in Hough Transform

Post by cavernah »

Hi! I don't know what's the problem with the arrays, because I can write the result direct to a file, not in an array! If anyone can help, this is the code:

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);
        }
}
timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg »

I don't believe you can do this:

Code: Select all

    double rhoArray[dx][dy];
    int thetaArray[dx][dy];

    int xArray[rhoMax];
    int yArray[rhoMax];
In C++. Perhaps you should read up on dynamic array allocation.

http://www.cplusplus.com/doc/tutorial/dynamic.html
j0ck3
Knows some wx things
Knows some wx things
Posts: 29
Joined: Fri Oct 10, 2008 6:44 am

Post by j0ck3 »

I was in the same situation as you a while ago and maybe you should consider familiarising yourself with a matrix library, especially since it seems you're going to do some image processing stuff.
cavernah
In need of some credit
In need of some credit
Posts: 6
Joined: Mon Jan 19, 2009 3:32 am
Location: Brazil

Post by cavernah »

timg wrote:I don't believe you can do this:

Code: Select all

    double rhoArray[dx][dy];
    int thetaArray[dx][dy];

    int xArray[rhoMax];
    int yArray[rhoMax];
In C++. Perhaps you should read up on dynamic array allocation.

http://www.cplusplus.com/doc/tutorial/dynamic.html
ok! I get it! And sorry, but I'm a newbie in C++ and wxWidgets! :oops:
Post Reply