Can you temporary grant a user permission to avoid captchas in drupal 7?
There are basic problems with your approach:


All anon users are one user for Drupal. They share common UID 0, so they are one user. And HTTP is a stateless protocol, so you can't decide "it's the same user" basing on connection. In Drupal 7 sessions are not guaranteed for anonymous users, so you can't use them reliably for that purpose either.
If you will try to modify $user->roles, it will add a role for current http call all right, but it will not regenerate caches, like admin/reports/status/rebuild or views caches based on roles.
hook_init docs says: This hook is not run on cached pages.


So, this is no-go by design, and if you need to give some privileges or options by browser session, you need to implement your own solutions, like cookies. There is a list of modules that works that way, you can use their code for reference.