There are many methods for camera calibration, but this uses a linear method that has pedagogical value.
The methods used is from "Robot Modeling and Control" by Spong, Vidgasgar and Hutchinson. This is the same methods as Tsai's http://people.csail.mit.edu/bkph/articles/Tsai_Revisited.pdf Tsai, Roger Y. (1986) "An Efficient and Accurate Camera Calibration Technique for 3D Machine Vision", Proceedings of IEEE Conference on Computer Vision and Pattern Recognition, Miami Beach, FL, 1986, pp. 364-374.
This code requires an image in the working directory named 'imageFilename.jpg'. It also requires the function gather3Ddata.m and findOrthocenter.m.
The user must manually enter the world [x,y,z] coordinates in the top of the function gather3Ddata.m.
Aaron T. Becker's Robot Swarm Lab (2019). Camera Calibration (Linear Method) (https://www.mathworks.com/matlabcentral/fileexchange/69699-camera-calibration-linear-method), MATLAB Central File Exchange. Retrieved .
Create scripts with code, output, and formatted text in a single executable document.