Filestorage for Opencv Python API

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

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.

Reading image file (file storage object) using OpenCV

I had similar issues while using opencv with flask server, for that first i saved the image to disk and read that image using saved filepath again using cv.imread()

Here is a sample code:

data =request.files['file']
filename = secure_filename(file.filename) # save file
filepath = os.path.join(app.config['imgdir'], filename);
file.save(filepath)
cv.imread(filepath)

But now i have got even more efficient approach from here by using cv.imdecode() to read image from numpy array as below:

#read image file string data
filestr = request.files['file'].read()
#convert string data to numpy array
file_bytes = numpy.fromstring(filestr, numpy.uint8)
# convert numpy array to image
img = cv.imdecode(file_bytes, cv.IMREAD_UNCHANGED)


Related Topics



Leave a reply



Submit