Search code examples
python-3.xopencvfile-storage

Will OpenCV 3.2+ FileStorage save the SimpleBlobDetector_create object in XML or YML?


I am fairly new to OpenCV 3+ in Python. It looks to me that FileStorage under Python does not support, for example, a writeObj() method. Is it possible to save the SimpleBlobDetector_create to an XML or YAML file using OpenCV 3+ in Python? Another way to put it is this: using Python OpenCV, can I save XML/YAML data that is not a numpy array or a scalar (e.g. an object)?


Solution

  • I was making the problem much harder than necessary. The solution is simple:

    # Setup SimpleBlobDetector parameters.
    params = cv.SimpleBlobDetector_Params()
    
    # Change desired parameters
    params.minThreshold = 20
    params.maxThreshold = 220
    
    # Create the blob detector
    detect = cv.SimpleBlobDetector_create(params)
    
    # Write detector parameters to .yml file
    fs_write = cv.FileStorage('blob_params_modified.yml',
                              cv.FILE_STORAGE_WRITE)
    detect.write(fs_write)
    fs_write.release()
    

    You can read this file in as input instead of fiddling with the code every time you want to tweak a parameter.