|
| 1 | +Color Blob Concepts |
| 2 | +=================== |
| 3 | + |
| 4 | +Color Blobs |
| 5 | +----------- |
| 6 | + |
| 7 | +An image can be evaluated by its **groupings of similar colors**. |
| 8 | + |
| 9 | +The smallest unit of any digital image is a **pixel**: a tiny square of one |
| 10 | +particular color. |
| 11 | + |
| 12 | +Each grouping or cluster of similar-colored pixels is called a **Blob**, which |
| 13 | +can be irregular in size and shape. |
| 14 | + |
| 15 | +Forming a Blob is done automatically by the software. It seeks pixels of |
| 16 | +similar color that are **contiguous** -- touching each other along an edge, not |
| 17 | +just at a corner. |
| 18 | + |
| 19 | +.. figure:: images/10-Blobs-formation.png |
| 20 | + :width: 75% |
| 21 | + :align: center |
| 22 | + :alt: Blob Formation Visualization |
| 23 | + |
| 24 | + Blob Formation Visualization |
| 25 | + |
| 26 | +There are 9 Blobs here, not 4. Some are very small, just one pixel each. |
| 27 | + |
| 28 | +The 5 pixels at top right, for example, are not contiguous (edges joined), so |
| 29 | +they are not joined to form a larger Blob. |
| 30 | + |
| 31 | +The above simple example has only 2 colors: black and white. For FTC, the |
| 32 | +definition of "similar" colors is a range specified by you. |
| 33 | + |
| 34 | +.. figure:: images/20-Blobs-red-chair.png |
| 35 | + :width: 75% |
| 36 | + :align: center |
| 37 | + :alt: Defining Blobs from an image of a red chair |
| 38 | + |
| 39 | + Blobs from a Red Chair image |
| 40 | + |
| 41 | +In the above example, the chair surfaces are not **exactly** the same shade of |
| 42 | +red. But with a **target** definition "close to red" or "mostly red", the |
| 43 | +software can form reasonable Blobs for further processing. |
| 44 | + |
| 45 | +Color Processing |
| 46 | +---------------- |
| 47 | + |
| 48 | +Now let's point the camera at an INTO THE DEEP game element called a |
| 49 | +**Sample**. |
| 50 | + |
| 51 | +.. figure:: images/30-Blobs-blue-basic.png |
| 52 | + :width: 75% |
| 53 | + :align: center |
| 54 | + :alt: Detecting Blob from a Blue SAMPLE |
| 55 | + |
| 56 | + Blob from a Blue SAMPLE |
| 57 | + |
| 58 | +Here the software was told to seek shades of blue. The orange rectangle |
| 59 | +encloses a Blob of blue color. |
| 60 | + |
| 61 | +But why doesn't the rectangle enclose the entire game piece? The software is |
| 62 | +processing only a certain **Region of Interest** or ROI. That's the white |
| 63 | +rectangle; its size and location are specified by you. |
| 64 | + |
| 65 | +Anything outside the ROI will not be considered part of any Blob that is |
| 66 | +detected. This can help you avoid detecting (unwanted) background objects. |
| 67 | + |
| 68 | +In the example above, the Blob was actually outlined in teal (blue-green |
| 69 | +color), very hard to see. Let's try another image: |
| 70 | + |
| 71 | +.. figure:: images/40-Blobs-single.png |
| 72 | + :width: 75% |
| 73 | + :align: center |
| 74 | + :alt: Finding Teal Outline |
| 75 | + |
| 76 | + Teal Outline of Blue Blob |
| 77 | + |
| 78 | +Now the teal outline of the blue Blob can be seen. Its shape is irregular, |
| 79 | +which can be difficult for your OpMode to evaluate. |
| 80 | + |
| 81 | +boxFit Rectangles |
| 82 | +----------------- |
| 83 | + |
| 84 | +The orange rectangle is drawn automatically by OpenCV, to give your OpMode a |
| 85 | +simpler geometric shape that represents the Blob. It's not **exactly** like |
| 86 | +the actual Blob, but hopefully still useful. |
| 87 | + |
| 88 | +The orange rectangle, called the **boxFit**, fits tightly around the extreme |
| 89 | +edges of the Blob. The boxFit is **not** required to stay inside the Region of |
| 90 | +Interest. In the above case, the best-fitting rectangle happens to stay inside |
| 91 | +the ROI. |
| 92 | + |
| 93 | +But here's another case: |
| 94 | + |
| 95 | +.. figure:: images/50-Blobs-tilted.png |
| 96 | + :width: 75% |
| 97 | + :align: center |
| 98 | + :alt: Showing Boxfit position |
| 99 | + |
| 100 | + New boxFit position |
| 101 | + |
| 102 | +Look very closely for the teal outline of the Blob, with its very rough lower |
| 103 | +edge. |
| 104 | + |
| 105 | +Here, the best-fitting rectangle (boxFit) is **tilted**, and is not contained |
| 106 | +inside the ROI. |
| 107 | + |
| 108 | +OpenCV provides all data for the boxFit, including its corner points, size, and |
| 109 | +tilt angle. It can even provide a fitted horizontal version of the boxFit |
| 110 | +rectangle, if you prefer not to handle a tilted boxFit. |
| 111 | + |
| 112 | +Now things get a bit more complicated: |
| 113 | + |
| 114 | +.. figure:: images/60-Blobs-two.png |
| 115 | + :width: 75% |
| 116 | + :align: center |
| 117 | + :alt: Detecting two blobs |
| 118 | + |
| 119 | + Detecting two blobs |
| 120 | + |
| 121 | +OpenCV detected **two Blobs**, each with a teal outline and each with a boxFit. |
| 122 | + |
| 123 | +Your OpMode will need to "decide" which boxFit is important and which to |
| 124 | +ignore. Fortunately, OpenCV provides tools to **filter out** certain unwanted |
| 125 | +results. After filtering, your OpMode can **sort** the remaining results, to |
| 126 | +focus on the highest priority. |
| 127 | + |
| 128 | +With these tools, your OpMode could handle even a "busy" result like this one: |
| 129 | + |
| 130 | +.. figure:: images/70-Blobs-many.png |
| 131 | + :width: 75% |
| 132 | + :align: center |
| 133 | + :alt: Many blob detections |
| 134 | + |
| 135 | + Many Blob Detections |
| 136 | + |
| 137 | +Your programming tasks will include: |
| 138 | + |
| 139 | +* determine which boxFit is most relevant, |
| 140 | +* evaluate its data, and |
| 141 | +* take robot action accordingly. |
| 142 | + |
| 143 | +Now try the Sample OpMode for the :doc:`Color Locator <../color-locator-discover/color-locator-discover>` processor. |
| 144 | + |
| 145 | +============ |
| 146 | + |
| 147 | +* Questions, comments and corrections to [email protected]* |
0 commit comments