It's a common myth that chameleons change skin colour to match their surroundings. Most chameleons skin have similar colours to their surroundings - they look like branches or leaves and has nothing to do with their vision. They only adjust how bright or dark their skin appears, based on the amount of light. Their natural camouflage is their only defence against predators.
Some chameleons sometimes try to appear as colourful as possible to either attract a mate or scare off an opponent. While the males show off a dazzling display of colours to attract the female, the female also uses colour to tell the male whether she likes him or not! If the female appears dark and black, it means that she is not interested in him and warning him to stay away.