Eek, that sounds stressful. Humping, when not sexual, can have a variety of meanings for dogs, but in your context it's likely due to stress, frustration, and/or over-arousal. I'd avoid punishing the behavior or trying to challenge him - anxiety doesn't get better when others force their will on the anxious individual. You might suppress this particular expression of anxiety, but it will turn up in other ways, and if you appear threatening to him, he may react aggressively.
If you're worried about his reaction to you, a tool to help you get him off your leg would be useful. A tennis racket or something else that you can wedge between you and him that keeps your hands away from him would help. Even a cookie sheet might work. Calmly separate him from your leg. Pairing the action of peeling him off with the cue "off" could eventually help him make the association, but ideally you want to prevent him from getting opportunities to start humping in the first place.
He would probably benefit from more exercise, stricter confinement, and other things to do that are less... awkward. Puzzle toys, stuffed Kongs or long-lasting chews might give him a better way to focus his energy and help him settle. Chewing releases endorphins, so it helps dogs self-calm, and the food rewards will help reinforce the acceptable behavior. I've found a squeaky ball to be pretty effective at redirecting a dog who is engaging in some kind of stress-related behavior, like barking. It might help in your case, too, if you can distract him and redirect him before he starts to hump. If you can replace his current stress reaction with something else, and then reward that something else, he'll start to make that choice more easily on his own and you should see the humping decrease.