If you know the focal length, find out the field of view from https://www.nikonians.org/reviews/fov-tables then it's just trigonometry:
pixel size = tan ( horiz.fov /2 ) * distance / image width in pixels.
So at 50 mm on 12 Mpx full frame at 5 m distance you get
tan (39.6°/2) * 5000mm / 4000 = 0.45 mm
At very close distance the focus will change the focal, but at a focusing distance greater than about 5x the focal length this effect should be minor so not many corrections are needed.
Distortion correction may reduce the field of view, but only if the software crops the image to avoid areas which have been "compressed" radially and which would result in empty regions, "pulled in" from outside the original image.
I searched and with OpenCV you are not forced to do it, here it states that "the cv2.getOptimalNewCameraMatrix() function will also return the region of interest, which can be used to crop the image", so if you don't want, you don't need to. See also on the official documentation for undistort and for the camera matrix. It looks to me you should be using "Alpha=1" for the matrix, and that's it.
Once you do, the resulting image should correspond exactly to the formula written above! it's the distortion (now no more present) that makes it deviate from it.
If greater accuracy is required, you need a reference tape in the photo itself.
As pointed out by Michael C, the magnification is not uniform in the field of view for rectilinear lenses and is higher at the corners. See wikipedia. Depending on the focal length used, it may be relevant or not: it should not be particularly relevant below 140° field of view (see here). Also, it is not much relevant if the plane of the object (assuming a flat object) is parallel to the plane of the camera.