Пример #1
0
//暴力匹配方式,在k2中找到k1的最佳匹配,hamming距离
// k1查询特征点,k2数据库特征点
int BruteForceMatch(const KeypointWithDesc& k1,
	const std::vector<KeypointWithDesc>&k2, int*dist)
{
	unsigned int distance[3] = { DESCRIPTOR_LENGTH * 8, DESCRIPTOR_LENGTH * 8, DESCRIPTOR_LENGTH * 8 };
	//最小距离, 次小距离,当前距离
	unsigned int index[3] = { 0 };
	unsigned short temp = 0;
	for (int i = 0; i < k2.size(); ++i)
	{
		distance[2] = 0;
		for (int j = 0; j < DESCRIPTOR_LENGTH/2; ++j)
		{
			//异或求海明距离
			temp = k1.m_d[j+1] ^ k2[i].m_d[j+1];
			temp = (temp << 8) | (k1.m_d[j] ^ k2[i].m_d[j]);
			distance[2] += __popcnt16(temp);
		}
		if (distance[2] < distance[1]){
			distance[1] = distance[2];
			index[1] = i;
			if (distance[1] <= distance[0]){
				distance[2] = distance[0];
				distance[0] = distance[1];
				distance[1] = distance[2];

				index[2] = index[0];
				index[0] = index[1];
				index[1] = index[2];
			}
		}
	}
	dist[0] = distance[0];
	dist[1] = distance[1];
	return index[0];
}
Пример #2
0
static inline int
popcnt(std::uint16_t n)
{
  return __popcnt16(n);
}