I ask to pet EVERYONE'S dog,
and then I ask the DOG if they want to have a pet, too. You just don't know--sometimes, a person will say, "Sure, pet him!", and the dog is not in the mood just then. Even dogs I see regularly who come up to me BEGGING for a pet, I acknowledge with a "Come for a lovey, huh?" before I put my hands on them.
You know something that would be great? Printed shirts for dog walking: "Ask if you can pet my dog!" if your dog is the flirty type, or "No, you can't pet him!" your baby's a little more standoffish.