<p>类似于Poik提供的解决方案。腌制前先打个电话。</p>
<pre><code>def patch_Keypoint_pickiling(self):
# Create the bundling between class and arguments to save for Keypoint class
# See : https://stackoverflow.com/questions/50337569/pickle-exception-for-cv2-boost-when-using-multiprocessing/50394788#50394788
def _pickle_keypoint(keypoint): # : cv2.KeyPoint
return cv2.KeyPoint, (
keypoint.pt[0],
keypoint.pt[1],
keypoint.size,
keypoint.angle,
keypoint.response,
keypoint.octave,
keypoint.class_id,
)
# C++ Constructor, notice order of arguments :
# KeyPoint (float x, float y, float _size, float _angle=-1, float _response=0, int _octave=0, int _class_id=-1)
# Apply the bundling to pickle
copyreg.pickle(cv2.KeyPoint().__class__, _pickle_keypoint)
</code></pre>
<p>除了代码,这里还有一个非常清晰的解释:<a href="https://stackoverflow.com/a/50394788/11094914">https://stackoverflow.com/a/50394788/11094914</a></p>
<p>请注意,如果您想将这个想法扩展到openCV的其他“不可接受”类,只需要构建一个类似于“pickle”keypoint的函数。确保以与构造函数相同的顺序存储属性。您可以考虑复制C++构造函数,即使在Python中,也像我一样。大多数C++和Python构造函数似乎没有太大的区别。</p>
<p>我对“pt”元组有意见。然而,对于X和Y分离的坐标,存在C++构造函数,因此允许这种修复/处理。</p>