Hi,
I have to write a C++ Programm which is able to detect an elliptical part in a 2d laserscan.
My scaner gives x,y Data from the scene.
The next step after i have detected the elliptical Part is to say from which area of an completely elliptic circumference the detected part is.
I have breake down the Scan into segments which i check with the alglib::lsfitlinear().
But i think lsfitlinear is not the right method for this task because much segments of even lines are detected as an elliptical part. The sample data for lsfitlinear came from a scan segment representing the ellipse i'm searching for.
Now i have no idea how to continue or which method is the right for this task.
Here my code:
Code:
alglib::ae_int_t info;
alglib::ae_int_t M = 1;
alglib::real_1d_array c;
alglib::lsfitreport rep;
alglib::real_2d_array sample;
alglib::real_1d_array experimentalData;
//create segment from file
Segment seg = this->createSampleSegmentFromFile("./samples/sample.txt", 130);
//translate sample in the origin
double avgXdist = this->calcAvgXDistance(seg);
double avgYdist = this->calcAvgYDistance(seg);
this->transformer->translateSegment(seg, -avgXdist, -avgYdist);
//create real_2d_array sample
sample = this->createReal2DArrayFromSegment(seg);
Segment s;
ScanPoint p1;
ScanPoint p2;
for (int i = 0; i < scan->getSegments()->size(); i++)
{
s = scan->getSegments()->at(i);
p1 = s.getSegmentPoints()->at(0);
p2 = s.getSegmentPoints()->at(s.getSegmentPoints()->size() - 1);
s.setAvgDist(this->calcAvgDistance(s));
s.setEuclidainDist(this->calcEuclidDist(p1, p2));
//translate segment to be examined in the origin
double avgSegXdist = this->calcAvgXDistance(s);
double avgSegYdist = this->calcAvgYDistance(s);
this->transformer->translateSegment(s, -avgSegXdist, -avgSegYdist);
//create experimental data array
experimentalData = this->createReal1DArrayFormSegment(s);
//do fitting
if (experimentalData.length() <= sample.rows()
&& s.getAvgDist() <= 6000
&& s.getAvgDist() >= 1500
&& s.getEuclidianDist() <= 1800)
{
//rotate Segment 360°
for (int j = 0; j < 36; j++)
{
alglib::lsfitlinear(experimentalData, sample, experimentalData.length(),
M, info, c, rep);
//rotiere um 10°
this->transformer->rotateSegment(s, 10);
//std::cout<<"Fitting by: " << j << "°" << "\n";
}
scan->getSegments()->at(i).setAvgErr(rep.avgerror);
scan->getSegments()->at(i).setMaxErr(rep.maxerror);
if (scan->getSegments()->at(i).getAvgErr() < 150)
{
scan->getSegments()->at(i).setIsStation(true);
}
std::cout<<"is station: "<<scan->getSegments()->at(i).getIsStation()<<"\n";
std::cout<<"SegNr: " << i << " AvgERR: "<<rep.avgerror <<"\n";
std::cout<<"SegNr: " << i << " MaxERR: "<<rep.maxerror <<"\n";
std::cout<<"euclid Dist: " << s.getEuclidianDist() <<"\n";
}
else
{
std::cout<<"Segment NR: "<< i << "is to large" <<"\n\n";
}
}
PLEASE HELP! -.-