I wear headphones pretty much all the time while walking around town or on public transit, and I am more than happy to give out directions if I know the area and can be helpful. For me, it's not to keep people from bothering me, but to amuse myself with music and block out traffic sounds.
I think the secret is to catch a "friendly" person with headphones. I usually smile at people and make eye contact, so I think tourists (or other people unfamilliar with the area) know I'm the one to ask. If you can find someone like that, go for it.
When I am zoned out, sometimes a person will sort of wave their arm at me, so that I notice and can take out my headphones. I think if a person didn't want to help you, they'd ignore it and keep moving. So maybe try to wave at them, but be sure not to get in their way if they're in a hurry or otherwise unable/unwilling to give you directions.
In general, I definitely don't see a problem with asking someone who has headphones on. If they seem to be giving you "keep away" signals (walking faster, refusing to make eye contact) though, it's better to ask someone else.