Camouflage was absolutely not a goal of 18th century uniforms. When you are wheeling around infantry units like big blocks camouflage is more or less tactically irrelevant.
Furthermore, if they were trying to blend in with each other like one big homogeneous mass of infantry they wouldn't have given everyone hats in a contrasting color.
The goal of their uniforms wasn't to hide individuals within the environment, but to make it hard to discern individuals within the imposing mass of soldiers.
The goal of their uniforms (and other colorful uniforms of that era) was to make units visible to the commanders on their side, so that they could grasp the arrangement of the battlefield easily, and know where to e.g. send a messenger to relay orders.
That doesn't explain why early-modern generals adopted costumes with extremely distinctive hats. Napoleon's hat, for example, was meant to allow troops to discern him instantly.
Furthermore, if they were trying to blend in with each other like one big homogeneous mass of infantry they wouldn't have given everyone hats in a contrasting color.