在Python中将OpenCV对象保存在内存中 [英] Saving OpenCV object in memory in python

查看:274
本文介绍了在Python中将OpenCV对象保存在内存中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用使用OpenCV库和Python语言的Fisher Face算法训练人脸识别模型.

I am training a face recognition model using Fisher Face algorithm using OpenCV library and Python language.

   fisherFace = cv2.face.FisherFaceRecognizer_create()
   fisherFace.train(imagefaceList, np.array(labelsIndexList))

我想将此模型保存在文件/内存中.换句话说,我想保存"fisherface"对象.我已经尝试过使用保存该对象的pickle模块.我无法腌制和解开该对象.代码如下:

I want to save this model in file/memory. In other word i want to save 'fisherface' object. I have tried pickle module for saving this object using this. I am not able to pickle and unpickle this object.Code is as below:

class test(object):
    def __init__(self, a):
        self.a = a
def pickle_test(t):
    print('pickling a test instance...')
        return test, (t.a,)
copyreg.pickle(test, pickle_test)
t = test(f)
t1 = copy.copy(t)
t2 = pickle.dumps(t)

有什么方法可以保存经过训练的费希尔人脸算法模型,并通过加载相同模型进行人脸识别来在其他地方使用它?

Is there any way available that saves trained model for fisher face algorithm and use it at other place by loading same model for face recognition?

推荐答案

FaceRecognizer类具有save方法,该方法将xml/yml文件存储到磁盘中,并可以使用load方法加载.

FaceRecognizer class has a save method, that stores a xml/yml file into the disk that can be loaded with the load method.

这是类方法列表.

所以,您应该能够做到

fisherFace.save("model.xml")

将模型保存到文件. https://docs.opencv.org/3.0- last-rst/modules/face/doc/facerec_api.html

To save model to file. https://docs.opencv.org/3.0-last-rst/modules/face/doc/facerec_api.html

这篇关于在Python中将OpenCV对象保存在内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆