Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

sadly, you're out of luck here.

the c++ interface is using an ObjectDetection struct, which is problematic to wrap into python, using the current generator scripts, so the whole dpm module is left out.

short answer: sadly, you're out of luck here.here, using it "as is".

the c++ interface is using an ObjectDetection struct, which is problematic to wrap into python, using the current generator scripts, so the whole dpm module is left out.

long answer: if you're willing to "hack it", you'd have to change the interface to:

class CV_EXPORTS_W DPMDetector
{
public:

    struct CV_EXPORTS ObjectDetection
    {
        ObjectDetection();
        ObjectDetection( const Rect& rect, float score, int classID=-1 );
        Rect rect;
        float score;
        int classID;
    };

    CV_WRAP virtual bool isEmpty() const = 0;

    /** @brief Find rectangular regions in the given image that are likely to contain objects of loaded classes
    (models) and corresponding confidence levels.
    @param image An image.
    @param objects The detections: rectangulars, scores and class IDs.
    */
    virtual void detect(cv::Mat &image, CV_OUT std::vector<ObjectDetection> &objects) = 0;

    /** @brief an overload for python / java which does not expose the ObjectDetection struct
    **/
    CV_WRAP void detect(cv::Mat &image, 
              CV_OUT std::vector<Rect> &rects , 
              CV_OUT std::vector<float> &scores,
              CV_OUT std::vector<int> &classIds) 
    {
         vector<ObjectDetection> obj;
         detect(image, obj);
         for (size_t i=0; i<obj.size(); i++) 
         {
             rects.push_back(obj[i].rect);
             scores.push_back(obj[i].score);
             classIds.push_back(obj[i].classId);
         }
     }


    /** @brief Return the class (model) names that were passed in constructor or method load or extracted from
    models filenames in those methods.
     */
    CV_WRAP virtual std::vector<std::string> const& getClassNames() const = 0;

    /** @brief Return a count of loaded models (classes).
     */
    CV_WRAP virtual size_t getClassCount() const = 0;

    /** @brief Load the trained models from given .xml files and return cv::Ptr\<DPMDetector\>.
    @param filenames A set of filenames storing the trained detectors (models). Each file contains one
    model. See examples of such files here `/opencv_extra/testdata/cv/dpm/VOC2007_Cascade/`.
    @param classNames A set of trained models names. If it's empty then the name of each model will be
    constructed from the name of file containing the model. E.g. the model stored in
    "/home/user/cat.xml" will get the name "cat".
     */
    CV_WRAP static cv::Ptr<DPMDetector> create(std::vector<std::string> const &filenames,
            std::vector<std::string> const &classNames = std::vector<std::string>());

    virtual ~DPMDetector(){}
};

short answer: sadly, you're out of luck here, using it "as is".

the c++ interface is using an ObjectDetection struct, which is problematic to wrap into python, using the current generator scripts, so the whole dpm module is left out.

long answer: if you're willing to "hack it", you'd have to change the interface to:

class CV_EXPORTS_W DPMDetector
{
public:

    struct CV_EXPORTS ObjectDetection
    {
        ObjectDetection();
        ObjectDetection( const Rect& rect, float score, int classID=-1 );
        Rect rect;
        float score;
        int classID;
    };

    CV_WRAP virtual bool isEmpty() const = 0;

    /** @brief Find rectangular regions in the given image that are likely to contain objects of loaded classes
    (models) and corresponding confidence levels.
    @param image An image.
    @param objects The detections: rectangulars, scores and class IDs.
    */
    virtual void detect(cv::Mat &image, CV_OUT std::vector<ObjectDetection> &objects) = 0;

    /** @brief an overload for python / java which does not expose the ObjectDetection struct
    **/
    CV_WRAP void detect(cv::Mat &image, 
              CV_OUT std::vector<Rect> &rects , 
              CV_OUT std::vector<float> &scores,
              CV_OUT std::vector<int> &classIds) 
    {
         vector<ObjectDetection> obj;
         detect(image, obj);
         for (size_t i=0; i<obj.size(); i++) 
         {
             rects.push_back(obj[i].rect);
             scores.push_back(obj[i].score);
             classIds.push_back(obj[i].classId);
         }
     }


    /** @brief Return the class (model) names that were passed in constructor or method load or extracted from
    models filenames in those methods.
     */
    CV_WRAP virtual std::vector<std::string> const& getClassNames() const = 0;

    /** @brief Return a count of loaded models (classes).
     */
    CV_WRAP virtual size_t getClassCount() const = 0;

    /** @brief Load the trained models from given .xml files and return cv::Ptr\<DPMDetector\>.
    @param filenames A set of filenames storing the trained detectors (models). Each file contains one
    model. See examples of such files here `/opencv_extra/testdata/cv/dpm/VOC2007_Cascade/`.
    @param classNames A set of trained models names. If it's empty then the name of each model will be
    constructed from the name of file containing the model. E.g. the model stored in
    "/home/user/cat.xml" will get the name "cat".
     */
    CV_WRAP static cv::Ptr<DPMDetector> create(std::vector<std::string> const &filenames,
            std::vector<std::string> const &classNames = std::vector<std::string>());

    virtual ~DPMDetector(){}
};