问题描述
我正在研究一个系统,该系统使用本地特征转换算法来识别对象。对于每个数据集,每个对象都有两个图像。我的管道如下:
- 从查询数据集中的图片(大小为n)中提取描述符并存储描述符
- 从训练数据集中的图像(大小为m)中提取描述符并存储描述符
- 将查询描述符与训练描述符匹配
- 对于每个匹配重复项,应用比率测试仅提取良好的特征
- 存储良好匹配/所有匹配的比率(1.0表示查询中所有匹配与火车完全匹配的100%)
这里有一些代码来说明该过程。我正在将Python和OpenCV一起用于管道。
nfeatures = 1000 # sift object created with nfeatures=1000
query_descs = np.zeros((nfeatures,128,len(query_files)),dtype=np.uint8) # SIFT descriptors are 128 Bytes long
train_descs = np.zeros((nfeatures,len(train_files)))
for i,file in enumerate(query_files): # List of query-files
img = cv2.imread(file,0) # Read grayscale
kpts,desc = sift.detectAndCompute(img,None)
query_descs[:,:,i] = desc
for i,file in enumerate(train_files): # List of query-files
img = cv2.imread(file,0)
kpts,None)
train_descs[:,i] = desc
scores = np.zeros((len(query_files),len(train_files))
for i in range(scores.shape[0]):
for j in range(scores.shape[1]):
matches = matcher.knnMatch(query_descs[:,i],train_descs[:,j],k=2)
good = 0
for m,n in matches:
if m.distance < threshold * n.distance:
good += 1
scores[i,j] = good / nfeatures
结果是一个大小为nxm的矩阵,通常每行包含一个强最大值。原则上,此最大值应该是正确的对象/图像。
我的问题是,我不需要知道哪些功能最匹配,而只有在匹配得很好的情况下,如果是这样,就增加变量good
。
通常如何执行两个图像匹配的质量?使用matcher.matchKnn()
似乎可以执行更多的工作,我想减少所有不必要的事情以获得最佳性能。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)