Commit ab72b24a authored by Vlad Shakhuro's avatar Vlad Shakhuro

Fix interface, add documentation

parent a546ba96
...@@ -53,25 +53,51 @@ namespace cv ...@@ -53,25 +53,51 @@ namespace cv
{ {
namespace xobjdetect namespace xobjdetect
{ {
//! @addtogroup xobjdetect
//! @{
/** @brief WaldBoost detector
*/
class CV_EXPORTS WBDetector { class CV_EXPORTS WBDetector {
public: public:
/** @brief Read detector from FileNode.
@param node FileNode for input
*/
virtual void read(const FileNode &node) = 0; virtual void read(const FileNode &node) = 0;
/** @brief Write detector to FileStorage.
@param fs FileStorage for output
*/
virtual void write(FileStorage &fs) const = 0; 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( virtual void train(
const std::string& pos_samples, const std::string& pos_samples,
const std::string& neg_imgs) = 0; 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( virtual void detect(
const Mat& img, const Mat& img,
std::vector<Rect> &bboxes, std::vector<Rect> &bboxes,
std::vector<double> &confidences) = 0; std::vector<double> &confidences) = 0;
/** @brief Create instance of WBDetector
*/
static Ptr<WBDetector> create();
virtual ~WBDetector(){} virtual ~WBDetector(){}
}; };
CV_EXPORTS Ptr<WBDetector> create_wbdetector();
//! @}
} /* namespace xobjdetect */ } /* namespace xobjdetect */
} /* namespace cv */ } /* namespace cv */
......
...@@ -365,7 +365,7 @@ int WaldBoost::predict(Ptr<CvFeatureEvaluator> eval, float *h) const ...@@ -365,7 +365,7 @@ int WaldBoost::predict(Ptr<CvFeatureEvaluator> eval, float *h) const
void WaldBoost::write(FileStorage &fs) const void WaldBoost::write(FileStorage &fs) const
{ {
fs << "waldboost" << "{"; fs << "{";
fs << "waldboost_params" fs << "waldboost_params"
<< "{" << "weak_count" << weak_count_ << "}"; << "{" << "weak_count" << weak_count_ << "}";
......
...@@ -212,7 +212,8 @@ void WBDetectorImpl::detect( ...@@ -212,7 +212,8 @@ void WBDetectorImpl::detect(
assert(confidences.size() == bboxes.size()); assert(confidences.size() == bboxes.size());
} }
Ptr<WBDetector> create_wbdetector() Ptr<WBDetector>
WBDetector::create()
{ {
return Ptr<WBDetector>(new WBDetectorImpl()); return Ptr<WBDetector>(new WBDetectorImpl());
} }
......
...@@ -16,11 +16,12 @@ int main(int argc, char **argv) ...@@ -16,11 +16,12 @@ int main(int argc, char **argv)
} }
string mode = argv[1]; string mode = argv[1];
Ptr<WBDetector> detector = create_wbdetector(); Ptr<WBDetector> detector = WBDetector::create();
if (mode == "train") { if (mode == "train") {
assert(argc == 5); assert(argc == 5);
detector->train(argv[3], argv[4]); detector->train(argv[3], argv[4]);
FileStorage fs(argv[2], FileStorage::WRITE); FileStorage fs(argv[2], FileStorage::WRITE);
fs << "waldboost";
detector->write(fs); detector->write(fs);
} else if (mode == "detect") { } else if (mode == "detect") {
assert(argc == 6); assert(argc == 6);
...@@ -28,7 +29,7 @@ int main(int argc, char **argv) ...@@ -28,7 +29,7 @@ int main(int argc, char **argv)
vector<double> confidences; vector<double> confidences;
Mat img = imread(argv[3], CV_LOAD_IMAGE_GRAYSCALE); Mat img = imread(argv[3], CV_LOAD_IMAGE_GRAYSCALE);
FileStorage fs(argv[2], FileStorage::READ); FileStorage fs(argv[2], FileStorage::READ);
detector->read(fs["waldboost"]); detector->read(fs.getFirstTopLevelNode());
detector->detect(img, bboxes, confidences); detector->detect(img, bboxes, confidences);
FILE *fhandle = fopen(argv[5], "a"); FILE *fhandle = fopen(argv[5], "a");
......
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