|
@@ -300,12 +300,7 @@ std::pair < QPoint *, QPoint * >StrengthLine::interpolateToEdge (int imgWidth, i
|
|
|
new QPoint (*p2));
|
|
|
}
|
|
|
|
|
|
-double StrengthLine::ea_score(const StrengthLine *sl, double imgWidth, double imgHeight) const
|
|
|
-{
|
|
|
- return this->distance(sl, imgWidth, imgHeight);
|
|
|
-}
|
|
|
-
|
|
|
-double StrengthLine::distance(const StrengthLine *sl, double imgWidth, double imgHeight) const
|
|
|
+float StrengthLine::ea_score(const StrengthLine *sl, double imgWidth, double imgHeight) const
|
|
|
{
|
|
|
std::srand(static_cast<unsigned int>(std::time(nullptr)+std::rand()));
|
|
|
std::pair < QPoint*, QPoint* > pointsSL1 = this->interpolateToEdge (imgWidth, imgHeight);
|
|
@@ -315,16 +310,40 @@ double StrengthLine::distance(const StrengthLine *sl, double imgWidth, double im
|
|
|
QPoint* p1SL2 = std::get < 0 > (pointsSL2);
|
|
|
QPoint* p2SL2 = std::get < 1 > (pointsSL2);
|
|
|
|
|
|
+ float u[2] = {p2SL1->x()-p1SL1->x(), p2SL1->y()-p1SL1->y()};
|
|
|
+ float v[2] = {p2SL2->x()-p1SL2->x(), p2SL2->y()-p1SL2->y()};
|
|
|
+ float normU = sqrt(u[0]*u[0]+u[1]*u[1]);
|
|
|
+ float normV = sqrt(v[0]*v[0]+v[1]*v[1]);
|
|
|
+ u[0]=u[0]/normU;
|
|
|
+ u[1]=u[1]/normU;
|
|
|
+ v[0]=v[0]/normV;
|
|
|
+ v[1]=v[1]/normV;
|
|
|
+ float angle = 0;
|
|
|
+
|
|
|
+ if((u[0]!=v[0]) || (u[1]!=v[1]))
|
|
|
+ {
|
|
|
+ float prodScal=u[0]*v[0]+u[1]*v[1];
|
|
|
+
|
|
|
+ // In case of number approximation...
|
|
|
+ if(prodScal>1)
|
|
|
+ prodScal=1;
|
|
|
+ if(prodScal<-1)
|
|
|
+ prodScal=-1;
|
|
|
+
|
|
|
+ angle = acos(prodScal);
|
|
|
+ }
|
|
|
+
|
|
|
+ float sT = 1 - (angle/(M_PI/2));
|
|
|
|
|
|
float midSL1X = ((p1SL1->x() + p2SL1->x())/2.0)/(imgWidth*1.0);
|
|
|
float midSL1Y = ((p1SL1->y() + p2SL1->y())/2.0)/(imgHeight*1.0);
|
|
|
float midSL2X = ((p1SL2->x() + p2SL2->x())/2.0)/(imgWidth*1.0);
|
|
|
float midSL2Y = ((p1SL2->y() + p2SL2->y())/2.0)/(imgHeight*1.0);
|
|
|
|
|
|
+ float sd = 1 - sqrt(((midSL1X-midSL2X)*(midSL1X-midSL2X))+((midSL1Y-midSL2Y)*(midSL1Y-midSL2Y)));
|
|
|
|
|
|
- return sqrt(((midSL1X-midSL2X)*(midSL1X-midSL2X))+((midSL1Y-midSL2Y)*(midSL1Y-midSL2Y)));
|
|
|
-
|
|
|
- //return std::rand();
|
|
|
+
|
|
|
+ return ((sT*sd)*(sT*sd));
|
|
|
}
|
|
|
|
|
|
StrengthLine* StrengthLine::getRandomLine (QImage * img)
|