Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

TagFamily.h

Go to the documentation of this file.
00001 #ifndef TAGFAMILY_H
00002 #define TAGFAMILY_H
00003 
00004 #include <climits>
00005 #include <cmath>
00006 #include <stdio.h>
00007 #include <vector>
00008 #include <map>
00009 
00010 #include "Vision/AprilTags/TagDetection.h"
00011 using namespace std;
00012 
00013 namespace AprilTags {
00014 
00015 //! Generic class for all tag encoding families
00016 class TagFamily {
00017 public:
00018   //! The codes array is not copied internally and so must not be modified externally.
00019   TagFamily(int bitsArg, int minimumHammingDistanceArg, const unsigned long long *codesArg);
00020 
00021   void setErrorRecoveryBits(int b);
00022 
00023   void setErrorRecoveryFraction(float v);
00024 
00025   /* if the bits in w were arranged in a d*d grid and that grid was
00026    * rotated, what would the new bits in w be?
00027    * The bits are organized like this (for d = 3):
00028    *
00029    *  8 7 6       2 5 8      0 1 2
00030    *  5 4 3  ==>  1 4 7 ==>  3 4 5    (rotate90 applied twice)
00031    *  2 1 0       0 3 6      6 7 8
00032    */
00033   static unsigned long long rotate90(unsigned long long w, int d);
00034 
00035   //! Computes the hamming distance between two unsigned long longs.
00036   static int hammingDistance(unsigned long long a, unsigned long long b);
00037 
00038   //! How many bits are set in the unsigned long long?
00039   static unsigned char popCountReal(unsigned long long w);
00040 
00041   static int popCount(unsigned long long w);
00042 
00043   //! Given an observed tag with code 'rCode', try to recover the id.
00044   /*  The corresponding fields of TagDetection will be filled in. */
00045   void decode(TagDetection& det, unsigned long long rCode) const;
00046 
00047   //! Prints the hamming distances of the tag codes.
00048   void printHammingDistances() const;
00049 
00050   //! Numer of pixels wide of the inner black border.
00051   int blackBorder;
00052 
00053   //! Number of bits in the tag. Must be n^2.
00054   int bits;
00055 
00056   //! Dimension of tag. e.g. for 16 bits, dimension=4. Must be sqrt(bits).
00057   int dimension;
00058 
00059   //! Minimum hamming distance between any two codes.
00060   /*  Accounting for rotational ambiguity? The code can recover
00061    *  (minHammingDistance-1)/2 bit errors.
00062    */
00063   int minimumHammingDistance;
00064 
00065   /* The error recovery value determines our position on the ROC
00066    * curve. We will report codes that are within errorRecoveryBits
00067    * of a valid code. Small values mean greater rejection of bogus
00068    * tags (but false negatives). Large values mean aggressive
00069    * reporting of bad tags (but with a corresponding increase in
00070    * false positives).
00071    */
00072   int errorRecoveryBits;
00073 
00074   //! The array of the codes. The id for a code is its index.
00075   std::vector<unsigned long long> codes;
00076 
00077   static const int  popCountTableShift = 12;
00078   static const unsigned int popCountTableSize = 1 << popCountTableShift;
00079   static unsigned char popCountTable[popCountTableSize];
00080 
00081   //! Initializes the static popCountTable
00082   static class TableInitializer {
00083   public:
00084     TableInitializer() {
00085       for (unsigned int i = 0; i < TagFamily::popCountTableSize; i++)
00086   TagFamily::popCountTable[i] = TagFamily::popCountReal(i);
00087     }
00088   } initializer;
00089 
00090   static std::map<std::pair<int,int>, TagFamily*> tagFamilyRegistry;
00091 };
00092 
00093 } // namespace
00094 
00095 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:51 2016 by Doxygen 1.6.3