简体   繁体   English

Python,将str转换为描述符surf类型

[英]Python, Convert str to descriptors surf type

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 我想从数据库中读取描述符冲浪类型,并使用它与使用surf方法的图像进行比较,问题是如何将描述符从字符串转换为ndarray数组

#!/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 pythonw -u“ surf v2.py”追溯(最近一次调用是最近的):文件“ surf v2.py”,第138行,位于desc2 = numpy.array(descriptor,dtype = numpy.float32).reshape((1,1 ))ValueError: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

That kind of depends on how the strings look. 这种类型取决于字符串的外观。 Maybe the numpy.fromstring will work. 也许numpy.fromstring将工作。 Otherwise check how the string is created and use the inverse function. 否则,请检查如何创建字符串并使用反函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM