To convert from pixels to mm we need a reference element.
The easiest solution is to take a first photo while holding a ruler or tape measure across your bars, and use this for calibration. Following photos don't need this if the camera or bike position doesn't change as we reuse the calibration ratio.
It may be possible to use a known length like wheel diameter or bar width for this, but this is difficult to get an accurate measurement from.