I'm working around SURF using OpenCV. I want to put the SURF descriptor into cache, so I have to serialize the descriptor and then deserialize it back to descriptor.
What I did is as follows:
[serialize]
kp, des = surf.detectAndCompute(img, None)
jm = json.dumps(des.tolist())
[deserialize]
du = json.loads(jm)
dn = np.asarray(du)
I printed the type of des
, dn
, which both are type of np.ndarray
. Howerver, after the deserialization, I can't use the dn
to perform the knnMatch
, while using the original des
is ok.
There is an error:
OpenCV Error: Assertion failed (_queryDescriptors.type() == trainDescType) in knnMatchImpl, file /home/zibo/opencv/modules/features2d/src/matchers.cpp, line 722
It seems that, the original descriptor des
is not just an type of numpy.ndarray
. I searched the OpenCV codes but don't find the answer yet.
So, can anyone help. How to serialize and deserialize SURF descriptor?
When you convert the loaded data to array, set data type to float32.
dn = np.asarray(du, dtype = np.float32)
I assume that 'np' here is the alias of 'numpy'.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.