discoverpixy
blobs.h
1 //
2 // begin license header
3 //
4 // This file is part of Pixy CMUcam5 or "Pixy" for short
5 //
6 // All Pixy source code is provided under the terms of the
7 // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
8 // Those wishing to use Pixy source code, software and/or
9 // technologies under different licensing terms should contact us at
10 // cmucam@cs.cmu.edu. Such licensing terms are available for
11 // all portions of the Pixy codebase presented here.
12 //
13 // end license header
14 //
15 #ifndef BLOBS_H
16 #define BLOBS_H
17 
18 #include <stdint.h>
19 #include "blob.h"
20 #include "pixytypes.h"
21 #include "colorlut.h"
22 #include "qqueue.h"
23 
24 #define MAX_BLOBS 100
25 #define MAX_BLOBS_PER_MODEL 20
26 #define MAX_MERGE_DIST 5
27 #define MIN_AREA 20
28 #define MIN_COLOR_CODE_AREA 10
29 #define MAX_CODED_DIST 6
30 #define MAX_COLOR_CODE_MODELS 5
31 
32 #define BL_BEGIN_MARKER 0xaa55
33 #define BL_BEGIN_MARKER_CC 0xaa56
34 
35 enum ColorCodeMode
36 {
37  DISABLED = 0,
38  ENABLED = 1,
39  CC_ONLY = 2,
40  MIXED = 3 // experimental
41 };
42 
43 class Blobs
44 {
45 public:
46  Blobs(Qqueue *qq, uint8_t *lut);
47  ~Blobs();
48  int blobify();
49  uint16_t getBlock(uint8_t *buf, uint32_t buflen);
50  uint16_t getCCBlock(uint8_t *buf, uint32_t buflen);
51  BlobA *getMaxBlob(uint16_t signature=0);
52  void getBlobs(BlobA **blobs, uint32_t *len, BlobB **ccBlobs, uint32_t *ccLen);
53  int setParams(uint16_t maxBlobs, uint16_t maxBlobsPerModel, uint32_t minArea, ColorCodeMode ccMode);
54  int runlengthAnalysis();
55 #ifndef PIXY
56  void getRunlengths(uint32_t **qvals, uint32_t *len);
57 #endif
58 
59  ColorLUT m_clut;
60  Qqueue *m_qq;
61 
62 private:
63  int handleSegment(uint8_t signature, uint16_t row, uint16_t startCol, uint16_t length);
64  void endFrame();
65  uint16_t combine(uint16_t *blobs, uint16_t numBlobs);
66  uint16_t combine2(uint16_t *blobs, uint16_t numBlobs);
67  uint16_t compress(uint16_t *blobs, uint16_t numBlobs);
68 
69  bool closeby(BlobA *blob0, BlobA *blob1);
70  int16_t distance(BlobA *blob0, BlobA *blob1);
71  void sort(BlobA *blobs[], uint16_t len, BlobA *firstBlob, bool horiz);
72  int16_t angle(BlobA *blob0, BlobA *blob1);
73  int16_t distance(BlobA *blob0, BlobA *blob1, bool horiz);
74  void processCC();
75  void cleanup(BlobA *blobs[], int16_t *numBlobs);
76  void cleanup2(BlobA *blobs[], int16_t *numBlobs);
77  bool analyzeDistances(BlobA *blobs0[], int16_t numBlobs0, BlobA *blobs[], int16_t numBlobs, BlobA **blobA, BlobA **blobB);
78  void mergeClumps(uint16_t scount0, uint16_t scount1);
79 
80  void printBlobs();
81 
82  CBlobAssembler m_assembler[CL_NUM_SIGNATURES];
83 
84  uint16_t *m_blobs;
85  uint16_t m_numBlobs;
86 
87  BlobB *m_ccBlobs;
88  uint16_t m_numCCBlobs;
89 
90  bool m_mutex;
91  uint16_t m_maxBlobs;
92  uint16_t m_maxBlobsPerModel;
93 
94  uint16_t m_blobReadIndex;
95  uint16_t m_ccBlobReadIndex;
96 
97  uint32_t m_minArea;
98  uint16_t m_mergeDist;
99  uint16_t m_maxCodedDist;
100  ColorCodeMode m_ccMode;
101  BlobA *m_maxBlob;
102 
103 #ifndef PIXY
104  uint32_t m_numQvals;
105  uint32_t *m_qvals;
106 #endif
107 };
108 
109 
110 
111 #endif // BLOBS_H
Definition: blob.h:270
Definition: pixytypes.h:133
Definition: pixytypes.h:156
Definition: blobs.h:43
Definition: colorlut.h:86