Camera calibration RMS error increases with more calibration frames

show us some of those images.

always store those pictures you capture at runtime, so you can analyze the dataset and run calibration again, on the same data.

the code is irrelevant, unless you have reason to suspect that the code is at fault.