Skip to content Skip to sidebar Skip to footer

Opencv, How To Pass Parameters Into Cv2.trackermedianflow_create Function?

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 docs.

Solution 1:

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())

Solution 2:

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){
    usingnamespace cv;

    Ptr<TrackerMedianFlow> retval;

    if(PyObject_Size(args) == 0 && (kw == NULL || PyObject_Size(kw) == 0))
    {
        ERRWRAP2(retval = cv::TrackerMedianFlow::create());
        returnpyopencv_from(retval);
    }

    returnNULL;
}

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.

Post a Comment for "Opencv, How To Pass Parameters Into Cv2.trackermedianflow_create Function?"