Talking to strangers isn't harassment; it's about having tact. The first words said should be benign; and then if the person seems shy or uninterested then don't continue.
Harassment is about 2 things to me:
1) If contact is initiated; do not make that contact something that could possibly make someone uncomfortable. Now you can't account for the fact someone might have extreme social anxiety, but avoid compliments or anything remotely about the person you are initiating contact with if you can avoid it. If you do say something about them, try to not sound too thirsty and try to make it non sexual.
2) If there is no sign they wanted to have contact initiated; don't continue with the contact. That's really the crux of what the term harassment really refers to; repeated unwanted contact. And notice the framing; "no sign they wanted contact initiated" is worded purposefully; they might not give obvious signs they are annoyed, or obvious signs they think you are harassing them... that doesn't matter, only continue contact if they give somewhat of an enthusiastic sign they actually want to talk.
1 requires a lot of tact and you might fail, but so does 2. Don't say anything if they ignore you, don't make a passive aggressive comment, don't apologize, just move on with your day.
Seems to have worked for me.
Also don't be a simp; you shouldn't want to date someone on sight, and if you do, work on that before ever attempting to talk to people.