How to use setInitialMask on TrackerCSRT?

前端 未结 4 801
小鲜肉
小鲜肉 2021-01-21 07:00

I am using TrackerCSRT for object tracking in a video, and currently I use the init method on the tracker to set the region of interest



        
相关标签:
4条回答
  • 2021-01-21 07:37

    Unfortunately, you can't.

    Just complementing @chungzuwalla answer, the tracker c++ code only uses mask if you set params.use_segmentation, but the Tracker python interface does not let you set params.

    0 讨论(0)
  • 2021-01-21 07:38

    i made a Pull Request to enable use of cv::TrackerCSRT::setInitialMask() for Python and Java.

    additionally may the following python code will be useful to play with params.

    tracker = cv2.TrackerCSRT_create()
    tracker.save("default_csrt.xml") // saves default values of the Tracker
                                        you can rename default_csrt.xml-> custom_csrt.xml 
                                        and change values in it and use it load params
    
    fs = cv2.FileStorage("custom_csrt.xml",cv2.FILE_STORAGE_READ)
    fn = fs.getFirstTopLevelNode()
    tracker.read(fn)
    
    0 讨论(0)
  • 2021-01-21 07:46

    I do not know of setInitialMask but in python you can select your region of interest using cv2.selectROI() method.

    A blog post on tracking objects in a video can be found here along with relevant code in a step-by-step approach.

    0 讨论(0)
  • 2021-01-21 07:53

    At the moment, you can't. But you could do it if you are prepared to rebuild OpenCV.

    The creation of Python bindings for OpenCV C++ modules is controlled by markup in the C++ files, as documented here. At the time of writing, the C++ declaration of setInitialMask() does not have the markup which causes a Python binding to be created for it, so it is inaccessible. I expect that is because the TrackerCSRT implementation is only a few months old, and that Python bindings will follow as it matures.

    However, if you are prepared to rebuild OpenCV on your system (which can be a little challenging if you haven't done it before), making setInitialMask() accessible from Python should be as simple as adding the CV_WRAP macro to that declaration (as explained in the above documentation) and rebuilding.

    There are quite a few guides online for how to build OpenCV, but since I haven't done this myself in a while and the methods are somewhat platform dependent, I won't recommend one.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题