Ask Your Question
0

Getting ORB descriptor values bit by bit

asked 2016-09-21 07:38:20 -0600

Reeven gravatar image

Hello!

Context: I am re-implementing the kmeans algorithm into a kmajority algorithm for binary descriptors, like ORB, based on hamming distances, inspired by this paper. This requires, for every binary descriptor in a cluster, to make each bit position of each descriptor "vote" for either 0 or 1 for the final value of that position in the cluster center.

Descriptor 1: 0 0 0 0 1 0 1 0 ...
Descriptor 2: 1 0 1 0 1 0 1 0 ...
Descriptor 3: 1 0 0 0 1 0 0 0 ...
---------------------------------
Center      : 1 0 0 0 1 0 1 0 ... <-- after majority vote for each bit

Question: ORB descriptors are stored in their mats as uchar, not bits. They are stored in a Mat of N rows (1 row per descriptor) and 32 columns (32 uchar for 256 bits). Obviously, I'm not interested in uchars, it's the bits I want. Therefore, is requesting the rows with:

bool* descriptor = myMat .ptr<bool>(rowIndex)

... the right approach if I want to iterate over a descriptor bit by bit instead of uchar by uchar? (I'm pretty unfamiliar with C++).

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-09-21 08:55:05 -0600

Eduardo gravatar image

updated 2016-09-23 03:54:20 -0600

You should get what you want with std::bitset. For example, the following code should print the descriptor values with 0/1:

std::vector< std::vector<std::bitset< 8 > > > binary_descriptors;
for(int i = 0; i < descriptors.rows; i++) {
  std::vector<std::bitset< 8 > > current_binary_descriptor;
  for(int j = 0; j < descriptors.cols; j++) {
    current_binary_descriptor.push_back( std::bitset< 8 >( descriptors.at<uchar>(i,j) ) );
  }
  binary_descriptors.push_back(current_binary_descriptor);
}

for(size_t i = 0; i < binary_descriptors.size(); i++) {
  for(size_t j = 0; j < binary_descriptors[i].size(); j++) {
    for(size_t k = 0; k < binary_descriptors[i][j].size(); k++) {
      std::cout << binary_descriptors[i][j][k] << " ";
    }
  }

  std::cout << std::endl;
}

There are 3 loops:

  • the first one for iterating over keypoint descriptors
  • the second one for iterating over the packed unsigned char descriptors for one keypoint descriptor
  • the last one for iterating over the 8 bits of an unsigned char.
edit flag offensive delete link more

Comments

Thank you, this is exactly what I needed.

Reeven gravatar imageReeven ( 2016-09-21 15:29:53 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-21 07:38:20 -0600

Seen: 783 times

Last updated: Sep 23 '16