【问题标题】:Python, Convert str to descriptors surf typePython,将 str 转换为描述符 surf 类型
【发布时间】:2013-12-07 16:33:47
【问题描述】:

我想从数据库中读取描述符 surf 类型,并使用 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) 

错误是:

pythonw -u "冲浪 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

退出代码:1

【问题讨论】:

    标签: python opencv surf descriptor


    【解决方案1】:

    这取决于字符串的外观。也许numpy.fromstring 会起作用。否则检查字符串是如何创建的并使用反函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 2011-06-22
      • 1970-01-01
      • 2012-04-16
      • 2013-09-05
      • 2012-06-14
      • 1970-01-01
      相关资源
      最近更新 更多