You'll need a sewing machine and some embroidery floss in a color that complements your pants, and regular sewing thread (in whatever color you want, this will show somewhat). You can also use appliques (pre-made or by using stitch witchery). I used some pre-made iron-on flowers I happened to have.
In this Instructable I will assume familiarity with sewing, and with your own sewing machine. If something is confusing, please comment and I'll do my best to clarify.
Step 1: Open the pants seam
Many commercial pants are stitched with two seams: a chain stitch to hold the pieces together, and an overlock stitch to keep the edges from fraying. The overlock has to be cut pretty much all along its length, but a chain stitch, if you mess with it a little, will come completely unraveled from one end to the other. It's hard to tell which end to pull, though, so try each leg.
Open out your pants and draw a pattern on the inside, remembering that it will be mirror-image on the outside of the leg.
Step 2: Base Embroidery
Place the bobbin in the bobbin trace and make sure the floss will pull out through the usual manner. Put the bobbin trace in the machine and make a stitch by hand to bring the floss up through the foot plate in the usual manner. Loosen the upper thread tension a little, to about the level for a buttonhole. You don't want the embroidery floss pulled up through the fabric at all, but you also don't want loose loops of the needle thread hanging down.
Try out your settings on some scrap fabric. My pictures of this also show some unsuccessful attempts with a couple kinds of yarn, which was just too fat and fuzzy to work well in the bobbin.
Stitch on the inside of the pants, following the pattern you drew as closely or not-closely as you want. At any ends that don't run off an edge, pull the embroidery thread through the fabric and tie it off with the bobbin thread on the inside.
Step 3: Appliques
My pants are velvet, which makes the glue not stick very well. I chose to topstitch my appliques after ironing, for safety.
This kind of machine embroidery, where I'm making very small, curvy shapes (flower petals), I find easiest to do by dropping the feed dogs on the machine and using an embroidery foot. Dropping the feed dogs makes the machine not try to pull the fabric under the presser foot in a straight line, as is normal. This means you can move the fabric you're sewing in any direction with ease. The drawback is that you have to do all the work of moving it. This is also why you want an embroidery foot, which has a spring in it so it doesn't push down so hard as a regular foot. Even with the feed dogs down, it's hard to move fabric through the machine if the regular foot is in place.
I find the best technique is to use my finger muscles to move the fabric, rather than my arm muscles. The fine motor control of the fingers is more accurate than the gross motor control of the arms.
Step 4: Back together
Serge or zigzag the raw edges, and resew the hem. New pants from old!