本文整理汇总了C++中MatrixT::row方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixT::row方法的具体用法?C++ MatrixT::row怎么用?C++ MatrixT::row使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixT
的用法示例。
在下文中一共展示了MatrixT::row方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: candidate_hamming_distances
void Match_HashedDescriptions
(
const HashedDescriptions& hashed_descriptions1,
const MatrixT & descriptions1,
const HashedDescriptions& hashed_descriptions2,
const MatrixT & descriptions2,
IndMatches * pvec_indices,
std::vector<DistanceType> * pvec_distances,
const int NN = 2
) const
{
typedef L2_Vectorized<typename MatrixT::Scalar> MetricT;
MetricT metric;
static const int kNumTopCandidates = 10;
// Preallocate the candidate descriptors container.
std::vector<int> candidate_descriptors;
candidate_descriptors.reserve(hashed_descriptions2.hashed_desc.size());
// Preallocated hamming distances. Each column indicates the hamming distance
// and the rows collect the descriptor ids with that
// distance. num_descriptors_with_hamming_distance keeps track of how many
// descriptors have that distance.
Eigen::MatrixXi candidate_hamming_distances(
hashed_descriptions2.hashed_desc.size(), nb_hash_code_ + 1);
Eigen::VectorXi num_descriptors_with_hamming_distance(nb_hash_code_ + 1);
// Preallocate the container for keeping euclidean distances.
std::vector<std::pair<DistanceType, int> > candidate_euclidean_distances;
candidate_euclidean_distances.reserve(kNumTopCandidates);
// A preallocated vector to determine if we have already used a particular
// feature for matching (i.e., prevents duplicates).
std::vector<bool> used_descriptor(hashed_descriptions2.hashed_desc.size());
typedef matching::Hamming<stl::dynamic_bitset::BlockType> HammingMetricType;
static const HammingMetricType metricH = {};
for (int i = 0; i < hashed_descriptions1.hashed_desc.size(); ++i)
{
candidate_descriptors.clear();
num_descriptors_with_hamming_distance.setZero();
candidate_euclidean_distances.clear();
const auto& hashed_desc = hashed_descriptions1.hashed_desc[i];
// Accumulate all descriptors in each bucket group that are in the same
// bucket id as the query descriptor.
for (int j = 0; j < nb_bucket_groups_; ++j)
{
const uint16_t bucket_id = hashed_desc.bucket_ids[j];
for (const auto& feature_id : hashed_descriptions2.buckets[j][bucket_id])
{
candidate_descriptors.push_back(feature_id);
used_descriptor[feature_id] = false;
}
}
// Skip matching this descriptor if there are not at least NN candidates.
if (candidate_descriptors.size() <= NN)
{
continue;
}
// Compute the hamming distance of all candidates based on the comp hash
// code. Put the descriptors into buckets corresponding to their hamming
// distance.
for (const int candidate_id : candidate_descriptors)
{
if (!used_descriptor[candidate_id]) // avoid selecting the same candidate multiple times
{
used_descriptor[candidate_id] = true;
const HammingMetricType::ResultType hamming_distance = metricH(
hashed_desc.hash_code.data(),
hashed_descriptions2.hashed_desc[candidate_id].hash_code.data(),
hashed_desc.hash_code.num_blocks());
candidate_hamming_distances(
num_descriptors_with_hamming_distance(hamming_distance)++,
hamming_distance) = candidate_id;
}
}
// Compute the euclidean distance of the k descriptors with the best hamming
// distance.
candidate_euclidean_distances.reserve(kNumTopCandidates);
for (int j = 0; j < candidate_hamming_distances.cols() &&
(candidate_euclidean_distances.size() < kNumTopCandidates); ++j)
{
for(int k = 0; k < num_descriptors_with_hamming_distance(j) &&
(candidate_euclidean_distances.size() < kNumTopCandidates); ++k)
{
const int candidate_id = candidate_hamming_distances(k, j);
const DistanceType distance = metric(
descriptions2.row(candidate_id).data(),
descriptions1.row(i).data(),
descriptions1.cols());
candidate_euclidean_distances.push_back(std::make_pair(distance, candidate_id));
}
//.........这里部分代码省略.........