Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion include/detection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <memory>
#include <string>

#include "opencv2/core/core.hpp"
#include "opencv2/opencv.hpp"

class Detector {
public:
Expand All @@ -12,3 +12,13 @@ class Detector {
virtual void Detect(const cv::Mat& frame, std::vector<cv::Rect>& objects,
std::vector<double>& scores) = 0;
};

class CascadeDetector : public Detector {
public:
virtual bool Init(const std::string& model_file_path);
virtual void Detect(const cv::Mat& frame, std::vector<cv::Rect>& objects,
std::vector<double>& scores);

protected:
cv::CascadeClassifier detector;
};
24 changes: 24 additions & 0 deletions src/detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,31 @@ using std::shared_ptr;
using namespace cv;

shared_ptr<Detector> Detector::CreateDetector(const string& name) {
if (name == "cascade") {
return std::make_shared<CascadeDetector>();
}
std::cerr << "Failed to create detector with name '" << name << "'"
<< std::endl;
return nullptr;

}

bool CascadeDetector::Init(const std::string& model_file_path)
{
if (detector.load(model_file_path)==true)
{
return true;
}
else return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (detector.load(model_file_path))
{
  return true;
}
return false;

}

void CascadeDetector::Detect(const cv::Mat& frame, std::vector<cv::Rect>& objects,
std::vector<double>& scores)
{
std::vector<int> scores_int;
detector.detectMultiScale(frame, objects, scores_int);
scores.resize(scores_int.size());
for (std::vector<int>::size_type i = 0; i < scores_int.size(); ++i) {
scores[i] = scores_int[i];
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::copy(scores_int.begin(), scores_int.end(), scores.begin());

}