[英]Python, OpenCV :How to use features extracted via ORB for a classification model?
我有一组成千上万张图片(我从40张图片开始进行测试),并且我想构建一个分类器,以区分图片中的对象。 例如,这是我的狗的照片,邻居的狗的照片还是我的兄弟狗的照片。 我知道如何比较两张图片及其关键点,但是我不确定要使用ML模型中提取的功能。
因此,我开始使用OpenCV,并使用ORB来检测150个关键点。 据我了解,描述符具有每个关键点的信息,这就是我将要使用的功能。 因此,现在我对每个图像都有150个特征,每个特征数组为32。(150,32)。 我想把它放到RandomForestClassifer中,但是当我收到错误时>>>>
ValueError:使用序列设置数组元素。
狗是数据帧
# Init ORB
orb = cv2.ORB_create(nfeatures=150)
# Extract descriptors and put them in df
with tqdm(total=len(list(dogs.iterrows()))) as pbar:
for index, row in dogs.iterrows():
pbar.update(1)
im = dogs.at[index, 'filtered']
kp1, des1 = orb.detectAndCompute(im,None)
dogs.at[index, 'kp'] = kp1
dogs.at[index, 'des'] = des1
os.system('spd-say "Processing complete"')
X = dogs['des']
y = dogs['Id']
features = pd.DataFrame.from_records(X)
features['Id'] = dogs['Id']
X = features.drop('Id',1)
y = features['Id']
查看第一个图像的第一个特征
X[1][1]
array([0,201,130,153,84,131,172,71,22,1,90,2,168,202,32,64,121,42,34,144,82,186,65,215 ,52,38,154,64,149,10,176,136],dtype = uint8)
clf = RandomForestClassifier(n_jobs=-1)
clf.fit(X,y)
我从未在ML模型中使用数组作为功能,所以这可能只是一个简单的错误。 如果我由于某种误解而犯错,请告诉我。
RandomForestClassifier
以及大多数常规ML算法只能处理标量特征。 因此,为了使用您的数据,您需要对其进行展平,例如, import numpy as np np.flatten(features.values)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.