First off to aid in searching for more information, what you're referring to is called Photogrammetry.
From a single image you can't [reliably] measure anything - there's no way of being able to tell if you're looking at a photograph of a photograph (i.e. a flat object very close to the camera).
From 2 or more images you can recover some or all measurements up to a certain accuracy (except in some rare cases), provided you have correspondence information, i.e. you know what parts of the first image correspond to the same parts in the subsequent images. At least 7 different points are required, 8 or more strongly recommended.
There are algorithms to estimate correspondence and with enough images that contain strong distinctive features the results can be quite accurate. To get absolute (as opposed to relative) measurements the camera must be calibrated. There are many ways to do this, the easiest being shooting a calibration target of known size.
Since you're comfortable with programming there are various bits of code that implement these methods (as well as proprietary products with SDKs) search for wide baseline stereo, or structure from motion.
Finally if you know the distance to the object then you can obtain estimates of the size using trigonometry (provided you know the focal length), see this question for more details: How do I calculate the distance of an object in a photo?