我试图从opencv中挑选一些关键点对象。 Pickle似乎不支持这个,所以我试图通过copy_reg添加一个reduce方法:
key = cv2.KeyPoint
# Add pickle function to keypoints
def pickle_kp(kp):
return key, (kp.x, kp.y, kp._size, kp._angle,
kp._response, kp._octave, kp._class_id,)
copy_reg.pickle(key, pickle_kp, key)
kp = key(1, 1, 1, 1, 1, 1, 1)
pickle.dumps(kp)
我仍然得到酸洗错误:
pickle.dumps(kp)
File "/usr/lib/python2.7/pickle.py", line 1374, in dumps
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/usr/lib/python2.7/copy_reg.py", line 70, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle KeyPoint objects
是否不能以这种方式使用copy_reg?
谢谢!