0

How to dump a cv2 object (more preciely a list or a np.array containing these objects), for example keypoints (type: cv2.KeyPoint) or matches (type: cv2.DMatch), to a file on disk in order to import them later rather than re-runing a time consumming (several hours up to days on a low end computer) algorithm on a lot of images (> 50'000)?

It doesn't work with (c)Pickle. Typical errors are:

PicklingError: Can't pickle <type 'cv2.KeyPoint'>: it's not the same object as cv2.KeyPoint

or

PicklingError: Can't pickle <type 'cv2.DMatch'>: it's not the same object as cv2.DMatch

And I can not find any dump or saving/export method on cv2.

The script runs using Python 2.7 on both Ubuntu 16.04 and Windows 7.

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
swiss_knight
  • 5,787
  • 8
  • 50
  • 92
  • Possible duplicate of [Pickle error cv2.Boost](https://stackoverflow.com/questions/50337569/pickle-error-cv2-boost) (has an answer, but was asked after this question, and is not KeyPoint-specific - but nor is the title of this question) – jtlz2 Apr 03 '19 at 09:21

1 Answers1

0

If you are insistent on saving Keypoints in a text/pickle file, then you must convert the Keypoint object so that it is pickle-able.

Use the SO answer here to break up the object into a pickle-able format and to load it back to your code.

Shawn Mathew
  • 2,198
  • 1
  • 14
  • 31