SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
CVRaulMurOrb.cpp File Reference

Declares the Raul Mur ORB feature detector and descriptor. More...

#include <iterator>
#include <CVRaulMurExtNode.h>
#include <CVRaulMurOrb.h>
Include dependency graph for CVRaulMurOrb.cpp:

Go to the source code of this file.

Macros

#define GET_VALUE(idx)
 

Functions

static float IC_Angle (const CVMat &image, CVPoint2f pt, const vector< int > &u_max)
 Returns the angle of the image patch around a keypoint based on the center of gravity. More...
 
static void computeOrbDescriptor (const CVKeyPoint &kpt, const CVMat &img, const CVPoint *pattern, uchar *desc)
 Calculate the Orb descriptor for a keypoint. More...
 
static void computeOrientation (const CVMat &image, CVVKeyPoint &keypoints, const vector< int > &umax)
 Compute the angle for a keypoint and save it. More...
 
static void computeDescriptors (const CVMat &image, CVVKeyPoint &keypoints, CVMat &descriptors, CVVPoint &pattern)
 Computes the descriptors for all passed keypoints. More...
 

Variables

const int PATCH_SIZE = 31
 
const int HALF_PATCH_SIZE = 15
 
const int EDGE_THRESHOLD = 19
 
const float factorPI = (float)(CV_PI / 180.f)
 
static int bit_pattern_31_ [256 *4]
 

Detailed Description

Declares the Raul Mur ORB feature detector and descriptor.

This File is based on the ORB Implementation of ORB_SLAM https://github.com/raulmur/ORB_SLAM2

Date
Spring 2017
Remarks
Please use clangformat to format the code. See more code style on https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
Authors
Pascal Zingg, Timon Tschanz, Michael Goettlicher, Marcus Hudritsch

Definition in file CVRaulMurOrb.cpp.

Macro Definition Documentation

◆ GET_VALUE

#define GET_VALUE (   idx)
Value:
center[cvRound(pattern[idx].x * b + pattern[idx].y * a) * step + \
cvRound(pattern[idx].x * a - pattern[idx].y * b)]
T step(T edge, T x)
Definition: Utils.h:251

Function Documentation

◆ computeDescriptors()

static void computeDescriptors ( const CVMat image,
CVVKeyPoint keypoints,
CVMat descriptors,
CVVPoint pattern 
)
static

Computes the descriptors for all passed keypoints.

Definition at line 792 of file CVRaulMurOrb.cpp.

796 {
797  descriptors = CVMat::zeros((int)keypoints.size(), 32, CV_8UC1);
798 
799  for (size_t i = 0; i < keypoints.size(); i++)
800  computeOrbDescriptor(keypoints[i],
801  image,
802  &pattern[0],
803  descriptors.ptr((int)i));
804 }
static void computeOrbDescriptor(const CVKeyPoint &kpt, const CVMat &img, const CVPoint *pattern, uchar *desc)
Calculate the Orb descriptor for a keypoint.

◆ computeOrbDescriptor()

static void computeOrbDescriptor ( const CVKeyPoint kpt,
const CVMat img,
const CVPoint pattern,
uchar *  desc 
)
static

Calculate the Orb descriptor for a keypoint.

Definition at line 62 of file CVRaulMurOrb.cpp.

66 {
67 
68  float angle = (float)kpt.angle * factorPI;
69  float a = (float)cos(angle), b = (float)sin(angle);
70 
71  const uchar* center = &img.at<uchar>(cvRound(kpt.pt.y), cvRound(kpt.pt.x));
72  const int step = (int)img.step;
73 // Define a rotation invariant get_value function which gets the correct pixel for the comparison
74 #define GET_VALUE(idx) \
75  center[cvRound(pattern[idx].x * b + pattern[idx].y * a) * step + \
76  cvRound(pattern[idx].x * a - pattern[idx].y * b)]
77 
78  // clang-format off
79  // Do the actual comparisons
80  for (int i = 0; i < 32; ++i, pattern += 16)
81  {
82  int t0, t1, val;
83  t0 = GET_VALUE(0); t1 = GET_VALUE(1); val = t0 < t1;
84  t0 = GET_VALUE(2); t1 = GET_VALUE(3); val |= (t0 < t1) << 1;
85  t0 = GET_VALUE(4); t1 = GET_VALUE(5); val |= (t0 < t1) << 2;
86  t0 = GET_VALUE(6); t1 = GET_VALUE(7); val |= (t0 < t1) << 3;
87  t0 = GET_VALUE(8); t1 = GET_VALUE(9); val |= (t0 < t1) << 4;
88  t0 = GET_VALUE(10); t1 = GET_VALUE(11); val |= (t0 < t1) << 5;
89  t0 = GET_VALUE(12); t1 = GET_VALUE(13); val |= (t0 < t1) << 6;
90  t0 = GET_VALUE(14); t1 = GET_VALUE(15); val |= (t0 < t1) << 7;
91 
92  desc[i] = (uchar)val;
93  }
94  // clang-format on
95 
96 #undef GET_VALUE
97 }
#define GET_VALUE(idx)
const float factorPI

◆ computeOrientation()

static void computeOrientation ( const CVMat image,
CVVKeyPoint keypoints,
const vector< int > &  umax 
)
static

Compute the angle for a keypoint and save it.

Definition at line 436 of file CVRaulMurOrb.cpp.

439 {
440  for (CVVKeyPoint::iterator keypoint = keypoints.begin(),
441  keypointEnd = keypoints.end();
442  keypoint != keypointEnd;
443  ++keypoint)
444  {
445  keypoint->angle = IC_Angle(image, keypoint->pt, umax);
446  }
447 }
static float IC_Angle(const CVMat &image, CVPoint2f pt, const vector< int > &u_max)
Returns the angle of the image patch around a keypoint based on the center of gravity.

◆ IC_Angle()

static float IC_Angle ( const CVMat image,
CVPoint2f  pt,
const vector< int > &  u_max 
)
static

Returns the angle of the image patch around a keypoint based on the center of gravity.

Definition at line 27 of file CVRaulMurOrb.cpp.

30 {
31  int m_01 = 0, m_10 = 0;
32 
33  const uchar* center = &image.at<uchar>(cvRound(pt.y), cvRound(pt.x));
34 
35  // Treat the center line differently, v=0
36  for (int u = -HALF_PATCH_SIZE; u <= HALF_PATCH_SIZE; ++u)
37  m_10 += u * center[u];
38 
39  // Go line by line in the circuI853lar patch
40  int step = (int)image.step1();
41  for (int v = 1; v <= HALF_PATCH_SIZE; ++v)
42  {
43  // Proceed over the two lines
44  int v_sum = 0;
45  int d = u_max[(uint)v];
46  for (int u = -d; u <= d; ++u)
47  {
48  int val_plus = center[u + v * step], val_minus = center[u - v * step];
49  v_sum += (val_plus - val_minus);
50  m_10 += u * (val_plus + val_minus);
51  }
52  m_01 += v * v_sum;
53  }
54 
55  return fastAtan2((float)m_01, (float)m_10);
56 }
const int HALF_PATCH_SIZE

Variable Documentation

◆ bit_pattern_31_

int bit_pattern_31_[256 *4]
static

This is the hardcoded comparison pattern which the creators of ORB have found to give the best results.

Definition at line 103 of file CVRaulMurOrb.cpp.

◆ EDGE_THRESHOLD

const int EDGE_THRESHOLD = 19

Definition at line 22 of file CVRaulMurOrb.cpp.

◆ factorPI

const float factorPI = (float)(CV_PI / 180.f)

Definition at line 58 of file CVRaulMurOrb.cpp.

◆ HALF_PATCH_SIZE

const int HALF_PATCH_SIZE = 15

Definition at line 21 of file CVRaulMurOrb.cpp.

◆ PATCH_SIZE

const int PATCH_SIZE = 31

Definition at line 20 of file CVRaulMurOrb.cpp.