From ab72b24a007027f7a96092ed1b72e1d8b6cbd33c Mon Sep 17 00:00:00 2001 From: Vlad Shakhuro Date: Wed, 26 Aug 2015 10:30:18 +0300 Subject: [PATCH] Fix interface, add documentation --- .../xobjdetect/include/opencv2/xobjdetect.hpp | 28 ++++++++++++++++++- modules/xobjdetect/src/waldboost.cpp | 2 +- modules/xobjdetect/src/wbdetector.cpp | 3 +- .../waldboost_detector/waldboost_detector.cpp | 5 ++-- 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/modules/xobjdetect/include/opencv2/xobjdetect.hpp b/modules/xobjdetect/include/opencv2/xobjdetect.hpp index da4ecf451..45038ab24 100644 --- a/modules/xobjdetect/include/opencv2/xobjdetect.hpp +++ b/modules/xobjdetect/include/opencv2/xobjdetect.hpp @@ -53,25 +53,51 @@ namespace cv { namespace xobjdetect { +//! @addtogroup xobjdetect +//! @{ + +/** @brief WaldBoost detector +*/ class CV_EXPORTS WBDetector { public: + /** @brief Read detector from FileNode. + @param node FileNode for input + */ virtual void read(const FileNode &node) = 0; + + /** @brief Write detector to FileStorage. + @param fs FileStorage for output + */ virtual void write(FileStorage &fs) const = 0; + /** @brief Train WaldBoost detector + @param pos_samples Path to directory with cropped positive samples + @param neg_imgs Path to directory with negative (background) images + */ virtual void train( const std::string& pos_samples, const std::string& neg_imgs) = 0; + /** @brief Detect objects on image using WaldBoost detector + @param img Input image for detection + @param bboxes Bounding boxes coordinates output vector + @param confidences Confidence values for bounding boxes output vector + */ virtual void detect( const Mat& img, std::vector &bboxes, std::vector &confidences) = 0; + /** @brief Create instance of WBDetector + */ + static Ptr create(); + virtual ~WBDetector(){} }; -CV_EXPORTS Ptr create_wbdetector(); + +//! @} } /* namespace xobjdetect */ } /* namespace cv */ diff --git a/modules/xobjdetect/src/waldboost.cpp b/modules/xobjdetect/src/waldboost.cpp index 1e97a5bec..8c1394621 100644 --- a/modules/xobjdetect/src/waldboost.cpp +++ b/modules/xobjdetect/src/waldboost.cpp @@ -365,7 +365,7 @@ int WaldBoost::predict(Ptr eval, float *h) const void WaldBoost::write(FileStorage &fs) const { - fs << "waldboost" << "{"; + fs << "{"; fs << "waldboost_params" << "{" << "weak_count" << weak_count_ << "}"; diff --git a/modules/xobjdetect/src/wbdetector.cpp b/modules/xobjdetect/src/wbdetector.cpp index 82122e4b7..395ea1e48 100644 --- a/modules/xobjdetect/src/wbdetector.cpp +++ b/modules/xobjdetect/src/wbdetector.cpp @@ -212,7 +212,8 @@ void WBDetectorImpl::detect( assert(confidences.size() == bboxes.size()); } -Ptr create_wbdetector() +Ptr +WBDetector::create() { return Ptr(new WBDetectorImpl()); } diff --git a/modules/xobjdetect/tools/waldboost_detector/waldboost_detector.cpp b/modules/xobjdetect/tools/waldboost_detector/waldboost_detector.cpp index 51f9cfd5b..490cdd585 100644 --- a/modules/xobjdetect/tools/waldboost_detector/waldboost_detector.cpp +++ b/modules/xobjdetect/tools/waldboost_detector/waldboost_detector.cpp @@ -16,11 +16,12 @@ int main(int argc, char **argv) } string mode = argv[1]; - Ptr detector = create_wbdetector(); + Ptr detector = WBDetector::create(); if (mode == "train") { assert(argc == 5); detector->train(argv[3], argv[4]); FileStorage fs(argv[2], FileStorage::WRITE); + fs << "waldboost"; detector->write(fs); } else if (mode == "detect") { assert(argc == 6); @@ -28,7 +29,7 @@ int main(int argc, char **argv) vector confidences; Mat img = imread(argv[3], CV_LOAD_IMAGE_GRAYSCALE); FileStorage fs(argv[2], FileStorage::READ); - detector->read(fs["waldboost"]); + detector->read(fs.getFirstTopLevelNode()); detector->detect(img, bboxes, confidences); FILE *fhandle = fopen(argv[5], "a");