【发布时间】:2018-04-03 16:07:23
【问题描述】:
我使用compute() 函数提取特征并将它们添加到列表中。然后我尝试使用 NumPy 将所有特征转换为float32,以便它们可以与 OpenCV 一起用于分类。我得到的错误是:
ValueError: setting an array element with a sequence.
不太确定我能做些什么。我正在关注一本书并执行相同的步骤,只是他们使用 HOS 来提取特征。我正在提取特征并取回大小不一致的矩阵,但不确定如何使它们全部相等。相关代码(可能有轻微的语法错误,因为我从原始代码中截断了它):
def get_SURF_feature_vector(area_of_interest, surf):
# Detect the key points in the image
key_points = surf.detect(area_of_interest);
# Create array of zeros with the same shape and type as a given array
image_key_points = np.zeros_like(area_of_interest);
# Draw key points on the image
image_key_points = cv2.drawKeypoints(area_of_interest, key_points, image_key_points, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Create feature discriptors
key_points, feature_descriptors = surf.compute(area_of_interest, key_points);
# Plot Image and descriptors
# plt.imshow(image_key_points);
# Return computed feature description matrix
return feature_descriptors;
for x in range(0, len(data)):
feature_list.append(get_SURF_feature_vector(area_of_interest[x], surf));
list_of_features = np.array(list_of_features, dtype = np.float32);
【问题讨论】:
-
是不是函数格式不对?我看到你在函数之外引用了
area_of_interest。 -
是的,但这不是我想要的。想象一下,感兴趣的区域只是加载到函数中的任意图像。重点在于 surf.compute 创建的数据结构以及如何将其转换为 float32 数组。