There is another, simpler way to guarantee 19 survivals. Given that there are 19 people in line and that they are in a stressful situation, it is possible that one of the 19 would miscount and give a wrong cue. This would throw off all the line, and cause more executions. As well, the first person in line will have to count all the other hats, and would have to bend out of line to see (what if he was short?). This may draw attention from the guards, and they all might be executed.
So, a simpler way: The 1st person looks at the hat in front of him (the 2nd's hat) and says its color. This gives the 1st a 50/50 chance. But the 2nd in line now knows their color! If the 3rd person has the same color hat as the 2nd, then when the 2nd announces their number, the 2nd announces the color of his hat loudly (shouts). If not (2nd and 3rd hats are different), the 2nd announces his quietly (normal).
This way, each person apart from the 1st will know their color, and there will be no math and no visual difficulties. The differences in volume could easily be attributed to different people's reactions to stressful situations.
1: R/B Says B
2: B Says B (loud)
3: B Says B (soft)
4: R Says R (loud)
5: R Says R (soft)
6: B Says B......