OpenCV, How to pass parameters into cv2.TrackerMedianFlow_create function?

后端 未结 2 438
借酒劲吻你
借酒劲吻你 2021-01-22 02:10

I\'m trying to create MEDIANFLOW tracker with OpenCV3.3 using opencv-python with Python3.6. I need to pass some arguments into the constructor according to this page of OpenCV d

相关标签:
2条回答
  • 2021-01-22 02:44

    I search the intermediate code generated by cmake/make when compiling the OpenCV 3.3 for Python 3.5, just cannot find the methods to set the parameters for cv2.TrackerXXX.

    In modules/python3/pyopencv_generated_funcs.h, I find this function:

    static PyObject* pyopencv_cv_TrackerMedianFlow_create(PyObject* , PyObject* args, PyObject* kw)
    {
        using namespace cv;
    
        Ptr<TrackerMedianFlow> retval;
    
        if(PyObject_Size(args) == 0 && (kw == NULL || PyObject_Size(kw) == 0))
        {
            ERRWRAP2(retval = cv::TrackerMedianFlow::create());
            return pyopencv_from(retval);
        }
    
        return NULL;
    }
    

    This is to say, you cann't pass any parameter to cv::TrackerMedianFlow_create().

    In modules/python3/pyopencv_generated_types.h, I find this one:

    static PyGetSetDef pyopencv_TrackerMedianFlow_getseters[] =
    {
        {NULL}  /* Sentinel */
    };
    

    This to say, you have no way to change the parameters for Python wrapper by default, Unless you modified the source code and recompile it.

    0 讨论(0)
  • 2021-01-22 02:44

    You can customize Tracker parameters via FileStorage interface.

    import cv2
    
    # write
    tracker = cv2.TrackerMedianFlow_create()
    tracker.save('params.json')
    
    # write (another way)
    fs = cv2.FileStorage("params.json", cv2.FileStorage_WRITE)
    tracker.write(fs)
    fs.release()
    
    # read
    tracker2 = cv2.TrackerMedianFlow_create()
    fs = cv2.FileStorage("params.json", cv2.FileStorage_READ)
    tracker2.read(fs.getFirstTopLevelNode())
    
    0 讨论(0)
提交回复
热议问题