ArrayFire优化球体距离匹配

时间:2019-06-11 14:27:50

标签: python orb arrayfire

我有一个包含带有模型文件的图像的文件夹,为此我提取了ORB的关键点和描述符。模型文件不会经常更改,我需要将它们与相机中的图像进行比较,并将它们(具有ORB匹配的查找模板)与模型文件进行比较。 目前,我的代码如下所示:

def orb_compare(model_descriptors, img_kp, img_des, img_wpx, flann_matcher):
    matches = flann_matcher.knnMatch(img_des, model_descriptors[0], k=2)

    #calculate matches distance to get "good_matches"
    good_matches = orb_calc_matches(matches, distance_range=0.65)
    good_matches_count = len(good_matches)

    #calculate match score, based on which we make best prediction
    score = good_matches_count + int((good_matches_count / len(model_descriptors[0]) * 1000))

    return (score, good_matches_count, model_descriptors[3], model_descriptors[4])


def orb_calc_matches(matches, distance_range=0.65):
    good_matches = []
    queried_matches = set()     # quicker than lists (no indexes)/only unique elements

    for match in matches:
        if len(match) == 2:
            if ((match[0].trainIdx not in queried_matches) and (match[0].distance < distance_range * match[1].distance)):
                good_matches.append(match[0])
                queried_matches.add(match[0].trainIdx)
    return good_matches

并使用ThreadPoolExecutor并行运行以加快处理速度:

with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
                        for result in executor.map(orb_compare, self.orb_descriptors, repeat(kp), repeat(des), repeat(img_wpx), repeat(self.matcher)):
                            model_results.append(result)

有人可以解释出于性能原因如何转换orb_calc_matches函数以使用ArrayFire吗?并确认使用CUDA / GPU会更快吗?

0 个答案:

没有答案