Commit 07dc6d2b authored by Dmitry Kurtaev's avatar Dmitry Kurtaev

Return a convex hull from rotatedRectangleIntersection

parent 8488f2e2
......@@ -32,14 +32,13 @@ void NMSBoxes(const std::vector<Rect>& bboxes, const std::vector<float>& scores,
static inline float rotatedRectIOU(const RotatedRect& a, const RotatedRect& b)
{
std::vector<Point2f> inter, hull;
std::vector<Point2f> inter;
int res = rotatedRectangleIntersection(a, b, inter);
if (inter.empty() || res == INTERSECT_NONE)
return 0.0f;
if (res == INTERSECT_FULL)
return 1.0f;
convexHull(inter, hull);
float interArea = contourArea(hull);
float interArea = contourArea(inter);
return interArea / (a.size.area() + b.size.area() - interArea);
}
......
......@@ -219,13 +219,15 @@ int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& r
}
}
// Get rid of dupes
// Get rid of dupes and order points.
for( int i = 0; i < (int)intersection.size()-1; i++ )
{
float dx1 = intersection[i + 1].x - intersection[i].x;
float dy1 = intersection[i + 1].y - intersection[i].y;
for( size_t j = i+1; j < intersection.size(); j++ )
{
float dx = intersection[i].x - intersection[j].x;
float dy = intersection[i].y - intersection[j].y;
float dx = intersection[j].x - intersection[i].x;
float dy = intersection[j].y - intersection[i].y;
double d2 = dx*dx + dy*dy; // can be a really small number, need double here
if( d2 < samePointEps*samePointEps )
......@@ -235,6 +237,12 @@ int rotatedRectangleIntersection( const RotatedRect& rect1, const RotatedRect& r
intersection.pop_back();
j--; // restart check
}
else if (dx1 * dy - dy1 * dx < 0)
{
std::swap(intersection[i + 1], intersection[j]);
dx1 = dx;
dy1 = dy;
}
}
}
......
This diff is collapsed.
......@@ -124,17 +124,14 @@ void decode(const Mat& scores, const Mat& geometry, float scoreThresh,
const int height = scores.size[2];
const int width = scores.size[3];
const int planeSize = height * width;
float* scoresData = (float*)scores.data;
float* geometryData = (float*)geometry.data;
float* x0_data = geometryData;
float* x1_data = geometryData + planeSize;
float* x2_data = geometryData + planeSize * 2;
float* x3_data = geometryData + planeSize * 3;
float* anglesData = geometryData + planeSize * 4;
for (int y = 0; y < height; ++y)
{
const float* scoresData = scores.ptr<float>(0, 0, y);
const float* x0_data = geometry.ptr<float>(0, 0, y);
const float* x1_data = geometry.ptr<float>(0, 1, y);
const float* x2_data = geometry.ptr<float>(0, 2, y);
const float* x3_data = geometry.ptr<float>(0, 3, y);
const float* anglesData = geometry.ptr<float>(0, 4, y);
for (int x = 0; x < width; ++x)
{
float score = scoresData[x];
......@@ -142,7 +139,6 @@ void decode(const Mat& scores, const Mat& geometry, float scoreThresh,
continue;
// Decode a prediction.
// Multiple by 4 because feature maps are 4 time less than input image.
float offsetX = x * 4.0f, offsetY = y * 4.0f;
float angle = anglesData[x];
......@@ -159,11 +155,5 @@ void decode(const Mat& scores, const Mat& geometry, float scoreThresh,
detections.push_back(r);
confidences.push_back(score);
}
scoresData += width;
x0_data += width;
x1_data += width;
x2_data += width;
x3_data += width;
anglesData += width;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment