Loading model state into FaceRecognizer from memory or string in python opencv

1.3k views Asked by At

Is it possible to load the model for a FaceRecognizer from memory or a string rather than from a saved file. The API docs do not show a 'FromString or Buffer' version.

The current code loads from file:

model = cv2.createLBPHFaceRecognizer()
model.load('model.xml')

Some more background. The presisted models are stored in S3. I don't want to retrieve from S3 and then save to disk in order to use. I would rather load directly from s3 into the model or load the xml string/document into the model.

1

There are 1 answers

2
berak On BEST ANSWER

unfortunately, not possible from python ( cv2 ) atm.

while you can do it from c++ ,

string yml; // the whole schlepp in a string
FileStorage fs;
fs.open(yml,FileStorage::READ|FileStorage::MEMORY);
facereco->load(fs);
fs.release();

sad as it is, you can neither access FileStorage api, nor the FaceReco::load(FileStorage&) methods from python

(sidenote : at least you could resave them once from the facereco as yml.gz, to get the traffic down to 1/5 of the uncompressed xml)