Python, Convert str to descriptors surf type

298 views Asked by At

I want to read descriptors surf type from database, and uses it to compare to images using surf method, the problem is how to convert descriptors from string to ndarray array

#!/usr/bin/python
detector = cv2.SURF(400, 5, 5)
matcher = cv2.BFMatcher(cv2.NORM_L2)
kp1, desc1 = detector.detectAndCompute(img1, None)     
cursor.execute(" SELECT * FROM visage WHERE id=%s", 1)
row = cursor.fetchone()
descriptor=row[6]
desc2=numpy.array(descriptor, dtype = numpy.float32).reshape((1,1))
kp_pairs = match_images(kp1, desc1 , kp2, desc2) 

The error is:

pythonw -u "surf v2.py" Traceback (most recent call last): File "surf v2.py", line 138, in desc2=numpy.array(descriptor, dtype = numpy.float32).reshape((1,1)) ValueError: invalid literal for float(): [[ 1.55181286e-03 1.55181286e-03 -2.10662147e-05 ..., 1.82572391e-03 0.00000000e+00 0.00000000e+00] [ 7.83637588e-05 1.05563842e-03 3.83123639e-03 ..., 1.95306598e-03 0.0000000

Exit code: 1

1

There are 1 answers

0
littleimp On

That kind of depends on how the strings look. Maybe the numpy.fromstring will work. Otherwise check how the string is created and use the inverse function.