|
1 | 1 | (* |
2 | | -# ColorFinder |
3 | | -Methods to find and interact with complex color objects. |
| 2 | +(ColorFinder)= |
| 3 | +# TColorFinder |
| 4 | +Methods to find and interact with complex color objects on the {ref}`MainScreen`. |
| 5 | + |
| 6 | +* **TColorFinder Zoom** |
| 7 | + |
| 8 | + When designing a {ref}`TColorFinder` it's very important to keep in mind that |
| 9 | + all values that are not colors **are measured in pixels at 50% zoom**. |
| 10 | + |
| 11 | + It is okay to be slightly off, but the closer you are to 50% the better. |
| 12 | + |
| 13 | + This is important because when you use {ref}`TColorFinder.Find` methods, the |
| 14 | + values of the `TColorFinder` will be transformed into your current zoom and |
| 15 | + assumes 50% as the baseline. |
| 16 | + |
| 17 | + For example, say you want to `grow` the object by 54 pixels at 50%. |
| 18 | + At 0% zoom, 54 pixels is much much larger than 54 pixels at 50% zoom. |
| 19 | + Because of this we transform it, assuming that you gathered your measurements |
| 20 | + at 50% zoom and transform it to 0% zoom which in this example would be 19 pixels. |
| 21 | + |
| 22 | + So if you grow your object by 54 pixels at 50% zoom you will only grow it by |
| 23 | + 19 at 0% zoom. At 100% zoom you grow it by 148 pixels. And so on. |
| 24 | + |
| 25 | + ```{figure} ../../images/zoom.png |
| 26 | + A finder working at different zoom levels producing similar results. |
| 27 | + ``` |
| 28 | + |
| 29 | +* **TColorFinder Colors and ColorClusters** |
| 30 | + |
| 31 | + `TColorFinders` are extremely good at finding complex color objects because you |
| 32 | + can add multiple colors or color clusters and values to process what is found in |
| 33 | + a way that filters what you don't want out while keeping what you want. |
| 34 | + |
| 35 | + You can add as many colors and color clusters you want, but you should use a |
| 36 | + sensible amount as the more you add the slower your finder will be. |
| 37 | + If you need more than 5/6 colors and/or clusters together you might not be doing |
| 38 | + things right or you need a different approach. |
| 39 | + |
| 40 | + |
| 41 | +TODO: ADD COLOR AND COLORCLUSTERS USAGE EXAMPLE |
| 42 | +with the following figure or something similar: |
| 43 | + |
| 44 | +* **TRSObjectFinder.Colors** |
| 45 | + |
| 46 | + An color array which will searched for. Use ACA to acquire color(s). |
| 47 | + |
| 48 | + ```pascal |
| 49 | + Finder.Colors += CTS2(2503237, 20, 0.10, 0.14); // brown |
| 50 | + Finder.Colors += CTS2(5526875, 15, 0.19, 0.06); // grey |
| 51 | + ``` |
| 52 | + |
| 53 | + ```{figure} ../../images/color_array.png |
| 54 | + The two colors above found and merged together. |
| 55 | + ``` |
| 56 | + |
| 57 | +* **TRSObjectFinder.ColorClusters** |
| 58 | + |
| 59 | + An array of "color clusters" which will be merged together. Use ACA to acquire color(s). |
| 60 | + |
| 61 | + A "color cluster" consists of a `primary` and `secondary` color and a `distance` value. |
| 62 | + When searched for only `primary` colors within `distance` of `secondary` colors are returned. |
| 63 | + |
| 64 | +```pascal |
| 65 | +Finder.ColorClusters += [ |
| 66 | +CTS2(2503237, 20, 0.10, 0.14), // brown |
| 67 | +CTS2(5526875, 15, 0.19, 0.06), // grey |
| 68 | +2 // distance |
| 69 | +]; |
| 70 | +``` |
| 71 | + |
| 72 | + ```{figure} ../../images/color_cluster.png |
| 73 | + The above color cluster found where "brown" is within 2 pixels of "grey". |
| 74 | + ``` |
4 | 75 | *) |
5 | 76 |
|
6 | 77 | {$DEFINE SRLT_COLORFINDER_INCLUDED} |
|
12 | 83 | ## type TColorFinderTransformer |
13 | 84 | Helper record that helps transforming a {ref}`TColorFinder` after finding it's |
14 | 85 | colors and/or colors clusters. |
| 86 | + |
| 87 | +You can access the `TColorFinder` transformer through the |
| 88 | +`TColorFinder.Transformer` variable. |
| 89 | + |
| 90 | +* **TColorFinderTransformer.Grow** |
| 91 | + The amount to `Grow` what we found. This is useful for filling gaps. |
| 92 | + |
| 93 | + ```pascal |
| 94 | + Finder.Transformer.Grow := 2; |
| 95 | + ``` |
| 96 | + |
| 97 | + ```{figure} ../../images/grow.png |
| 98 | + Grow before and after. |
| 99 | + ``` |
| 100 | + |
| 101 | +* **TColorFinderTransformer.Erode** |
| 102 | + The amount to `Erode` what we found. |
| 103 | + This is useful for removing small amounts of noise. |
| 104 | + |
| 105 | + ```pascal |
| 106 | + Finder.Transformer.Erode := 2; |
| 107 | + ``` |
| 108 | + |
| 109 | + ```{figure} ../../images/erode.png |
| 110 | + Erode before and after. |
| 111 | + ``` |
| 112 | + |
| 113 | + `Erode` comes after `Grow` and they can be paired together for some powerful results. |
| 114 | + |
| 115 | + ```pascal |
| 116 | + Finder.Transformer.Grow := 3; |
| 117 | + Finder.Transformer.Erode := 4; |
| 118 | + ``` |
| 119 | + |
| 120 | + ```{figure} ../../images/grow_erode.png |
| 121 | + Grow paired with Erode. |
| 122 | + ``` |
| 123 | + |
| 124 | +* **TColorFinderTransformer.Distance** |
| 125 | + This is the distance that decides how multiple objects are grouped up. |
| 126 | + `Distance=5` would mean that points that are closer than or equal to 5 pixels |
| 127 | + away are considered close enough to merge into a singular group. |
| 128 | + |
| 129 | + ```pascal |
| 130 | + Finder.Transformer.Distance := 5; |
| 131 | + ``` |
| 132 | + |
| 133 | + ```{figure} ../../images/cluster_5.png |
| 134 | + Cluster distance **5** produces four individual chairs |
| 135 | + ``` |
| 136 | + |
| 137 | + ```pascal |
| 138 | + Finder.Transformer.Distance := 20; |
| 139 | + ``` |
| 140 | + |
| 141 | + ```{figure} ../../images/cluster_20.png |
| 142 | + Cluster distance **20** produces two sets of chairs |
| 143 | + ``` |
| 144 | + |
| 145 | +* **TColorFinderTransformer.ShortSide and TColorFinderTransformer.LongSide** |
| 146 | + Used to filter the final results. |
| 147 | + |
| 148 | + For each of the results, the bounding `TQuad` is used, `TQuads` have a |
| 149 | + **long** and a **short** side which is measured in pixels. |
| 150 | + Any match whose `TQuad` is not within the `ShortSize.Min`/`ShortSide.Max` and |
| 151 | + `LongSide.Min`/`LongSide.Max` will be removed from the final result. |
| 152 | + |
| 153 | + ```pascal |
| 154 | + // Removes matches where the short side isn't within 10 and 20 pixels |
| 155 | + Finder.MinShortSide := 10; |
| 156 | + Finder.MaxShortSide := 20; |
| 157 | + // Removes matches where the long side isn't within 20 and 40 pixels |
| 158 | + Finder.MinLongSide := 20; |
| 159 | + Finder.MaxLongSide := 40; |
| 160 | + ``` |
| 161 | + |
| 162 | + ```{figure} ../../images/bounding_rect.png |
| 163 | + Example bounding rectangle with a long and short side. |
| 164 | + ``` |
15 | 165 | *) |
16 | 166 | TColorFinderTransformer = record |
17 | 167 | Distance, Erode, Grow: Integer; |
|
0 commit comments