hi, im doing a stage 2 compsys paper in uni.
got stuck with the project
could some1 have a look at my code and tell me why there's segmentation fault, plz?
this project is simplified to find the white rectangle on the red wall of a given image.
my main:
[CODE=cpp] BMP bmpIn;
bmpIn.load("tes t3.jpg");
bmpIn.moveCurso rTo(0,30);
firstvertex = bmpIn.findFirst White();
one.x = firstvertex.x;
one.y = firstvertex.y;
cout<<one.x<<" "<<one.y<<e ndl;
jb = bmpIn.findVerti ces2(one.x, one.y);
lj = bmpIn.findVerti ces3(one.x, one.y);
cout<<jb.x<<"." <<jb.y<<endl;
cout<<lj.x<<"." <<lj.y<<endl;[/code]
where the cursor keeps track where we are. and all the declare stuff are not here
cpp file:
[code=cpp]OJ BMP::findVertic es2(int a , int b)
{
int x, y;
int c = 1;
OJ jb;
vector<int>sox;
vector<int>soy;
sox[0] = getCursorX();
soy[0] = getCursorY();
cout<<a<<" "<<b<<endl;
cout<<"hi"<<end l;
for (x = a; x < a + 30; x++){
for(y = b; y< 85;y++){
if (testwhite(x,y) ==1)
{
sox[c] = x;
soy[c] = y;
c++;
y = b;
x++;
cout<<"fk"<<end l;
}
if (sox[c] - sox[c -1] > 10 )
{
jb.x = sox[c-1];
jb.y = soy[c-1];
return jb;
cout<<"yuou"<<e ndl;
}
if (y == 84 )
{
jb.x = sox[c-1];
jb.y = soy[c-1];
cout<<"lol"<<en dl;
}
}}
}
OJ BMP::findVertic es3(int a , int b)
{
int x, y;
int c = 1;
OJ lj;
vector<int>hix;
vector<int>hiy;
hix[0] = getCursorX();
hiy[0] = getCursorY();
for (x = a; x > a + 30; x--){
for(y = b; y < 85;y++){
if (testwhite(x,y) ==1)
{
hix[c] = x;
hiy[c] = y;
c++;
y = b;
x++;
}
if (hix[c] - hix[c -1] > 10 )
{
lj.x = hix[c-1];
lj.y = hiy[c-1];
return lj;
}
if (y == 84 )
{
lj.x = hix[c-1];
lj.y = hiy[c-1];
}
}}
}[/CODE]
where OJ is a struct i created in the header file with x and y as its member
testwhite() is basically the red green and blue values for defining white.
got stuck with the project
could some1 have a look at my code and tell me why there's segmentation fault, plz?
this project is simplified to find the white rectangle on the red wall of a given image.
my main:
[CODE=cpp] BMP bmpIn;
bmpIn.load("tes t3.jpg");
bmpIn.moveCurso rTo(0,30);
firstvertex = bmpIn.findFirst White();
one.x = firstvertex.x;
one.y = firstvertex.y;
cout<<one.x<<" "<<one.y<<e ndl;
jb = bmpIn.findVerti ces2(one.x, one.y);
lj = bmpIn.findVerti ces3(one.x, one.y);
cout<<jb.x<<"." <<jb.y<<endl;
cout<<lj.x<<"." <<lj.y<<endl;[/code]
where the cursor keeps track where we are. and all the declare stuff are not here
cpp file:
[code=cpp]OJ BMP::findVertic es2(int a , int b)
{
int x, y;
int c = 1;
OJ jb;
vector<int>sox;
vector<int>soy;
sox[0] = getCursorX();
soy[0] = getCursorY();
cout<<a<<" "<<b<<endl;
cout<<"hi"<<end l;
for (x = a; x < a + 30; x++){
for(y = b; y< 85;y++){
if (testwhite(x,y) ==1)
{
sox[c] = x;
soy[c] = y;
c++;
y = b;
x++;
cout<<"fk"<<end l;
}
if (sox[c] - sox[c -1] > 10 )
{
jb.x = sox[c-1];
jb.y = soy[c-1];
return jb;
cout<<"yuou"<<e ndl;
}
if (y == 84 )
{
jb.x = sox[c-1];
jb.y = soy[c-1];
cout<<"lol"<<en dl;
}
}}
}
OJ BMP::findVertic es3(int a , int b)
{
int x, y;
int c = 1;
OJ lj;
vector<int>hix;
vector<int>hiy;
hix[0] = getCursorX();
hiy[0] = getCursorY();
for (x = a; x > a + 30; x--){
for(y = b; y < 85;y++){
if (testwhite(x,y) ==1)
{
hix[c] = x;
hiy[c] = y;
c++;
y = b;
x++;
}
if (hix[c] - hix[c -1] > 10 )
{
lj.x = hix[c-1];
lj.y = hiy[c-1];
return lj;
}
if (y == 84 )
{
lj.x = hix[c-1];
lj.y = hiy[c-1];
}
}}
}[/CODE]
where OJ is a struct i created in the header file with x and y as its member
testwhite() is basically the red green and blue values for defining white.
Comment