Added another member function which enables you to get the detection

strengths from the object_detector.
This commit is contained in:
Davis King 2011-12-21 19:47:26 -05:00
parent ca6bd2caa8
commit d53a37e770
2 changed files with 79 additions and 0 deletions

View File

@ -45,6 +45,14 @@ namespace dlib
const image_type& img
) const;
template <
typename image_type
>
void operator() (
const image_type& img,
std::vector<std::pair<double, rectangle> >& final_dets
) const;
template <typename T, typename U>
friend void serialize (
const object_detector<T,U>& item,
@ -72,6 +80,19 @@ namespace dlib
return false;
}
bool overlaps_any_box (
const std::vector<std::pair<double,rectangle> >& rects,
const dlib::rectangle& rect
) const
{
for (unsigned long i = 0; i < rects.size(); ++i)
{
if (boxes_overlap(rects[i].second, rect))
return true;
}
return false;
}
overlap_tester_type boxes_overlap;
matrix<double,0,1> w;
mutable image_scanner_type scanner;
@ -221,6 +242,41 @@ namespace dlib
return final_dets;
}
// ----------------------------------------------------------------------------------------
template <
typename image_scanner_type,
typename overlap_tester_type
>
template <
typename image_type
>
void object_detector<image_scanner_type,overlap_tester_type>::
operator() (
const image_type& img,
std::vector<std::pair<double, rectangle> >& final_dets
) const
{
final_dets.clear();
if (w.size() != 0)
{
std::vector<std::pair<double, rectangle> > dets;
const double thresh = w(scanner.get_num_dimensions());
scanner.load(img);
scanner.detect(w, dets, thresh);
for (unsigned long i = 0; i < dets.size(); ++i)
{
if (overlaps_any_box(final_dets, dets[i].second))
continue;
dets[i].first -= thresh;
final_dets.push_back(dets[i]);
}
}
}
// ----------------------------------------------------------------------------------------
}

View File

@ -99,6 +99,29 @@ namespace dlib
element 1 the next best, and so on.
!*/
template <
typename image_type
>
void operator() (
const image_type& img,
std::vector<std::pair<double, rectangle> >& dets
) const;
/*!
requires
- img == an object which can be accepted by image_scanner_type::load()
ensures
- performs object detection on the given image and stores the
detected objects into #dets. In particular, we will have that:
- #dets is sorted such that the highest confidence detections
come first. E.g. element 0 is the best detection, element 1
the next best, and so on.
- #dets.size() == the number of detected objects.
- #dets[i].first gives the "detection confidence", of the i-th
detection. This is the detection value output by the scanner
minus the threshold, therefore this is a value > 0.
- #dets[i].second == the bounding box for the i-th detection.
!*/
};
// ----------------------------------------------------------------------------------------