Is it rude to ask to pet strangers dogs?

Been doing this recently when I see a nice dog on a walk but some owners seemed to be a bit weirded out.