2017-10-17 00:16:52 +08:00
|
|
|
// This file is part of OpenCV project.
|
|
|
|
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
|
|
|
// of this distribution and at http://opencv.org/license.html.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017, Intel Corporation, all rights reserved.
|
|
|
|
// Third party copyrights are property of their respective owners.
|
|
|
|
|
|
|
|
#include "precomp.hpp"
|
2018-03-16 21:36:11 +08:00
|
|
|
#include "nms.inl.hpp"
|
2017-10-17 00:16:52 +08:00
|
|
|
|
2018-04-24 23:25:43 +08:00
|
|
|
#include <opencv2/imgproc.hpp>
|
|
|
|
|
2017-10-17 00:16:52 +08:00
|
|
|
namespace cv
|
|
|
|
{
|
|
|
|
namespace dnn
|
|
|
|
{
|
2017-10-17 16:24:50 +08:00
|
|
|
CV__DNN_EXPERIMENTAL_NS_BEGIN
|
|
|
|
|
|
|
|
static inline float rectOverlap(const Rect& a, const Rect& b)
|
|
|
|
{
|
|
|
|
return 1.f - static_cast<float>(jaccardDistance(a, b));
|
|
|
|
}
|
2017-10-17 00:16:52 +08:00
|
|
|
|
|
|
|
void NMSBoxes(const std::vector<Rect>& bboxes, const std::vector<float>& scores,
|
|
|
|
const float score_threshold, const float nms_threshold,
|
2017-10-17 16:24:50 +08:00
|
|
|
std::vector<int>& indices, const float eta, const int top_k)
|
2017-10-17 00:16:52 +08:00
|
|
|
{
|
2017-10-17 16:24:50 +08:00
|
|
|
CV_Assert(bboxes.size() == scores.size(), score_threshold >= 0,
|
|
|
|
nms_threshold >= 0, eta > 0);
|
|
|
|
NMSFast_(bboxes, scores, score_threshold, nms_threshold, eta, top_k, indices, rectOverlap);
|
2017-10-17 00:16:52 +08:00
|
|
|
}
|
|
|
|
|
2018-04-24 23:25:43 +08:00
|
|
|
static inline float rotatedRectIOU(const RotatedRect& a, const RotatedRect& b)
|
|
|
|
{
|
2018-05-01 02:51:33 +08:00
|
|
|
std::vector<Point2f> inter;
|
2018-04-24 23:25:43 +08:00
|
|
|
int res = rotatedRectangleIntersection(a, b, inter);
|
|
|
|
if (inter.empty() || res == INTERSECT_NONE)
|
|
|
|
return 0.0f;
|
|
|
|
if (res == INTERSECT_FULL)
|
|
|
|
return 1.0f;
|
2018-05-01 02:51:33 +08:00
|
|
|
float interArea = contourArea(inter);
|
2018-04-24 23:25:43 +08:00
|
|
|
return interArea / (a.size.area() + b.size.area() - interArea);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NMSBoxes(const std::vector<RotatedRect>& bboxes, const std::vector<float>& scores,
|
|
|
|
const float score_threshold, const float nms_threshold,
|
|
|
|
std::vector<int>& indices, const float eta, const int top_k)
|
|
|
|
{
|
|
|
|
CV_Assert(bboxes.size() == scores.size(), score_threshold >= 0,
|
|
|
|
nms_threshold >= 0, eta > 0);
|
|
|
|
NMSFast_(bboxes, scores, score_threshold, nms_threshold, eta, top_k, indices, rotatedRectIOU);
|
|
|
|
}
|
|
|
|
|
2017-10-17 16:24:50 +08:00
|
|
|
CV__DNN_EXPERIMENTAL_NS_END
|
2017-10-17 00:16:52 +08:00
|
|
|
}// dnn
|
|
|
|
}// cv
|