function [calib,ij_res] = pinhole_camera_fit(setup)
	% using the information provided in setup
	% which describes the camera and traverse setup
	% as well as measured positions of calibration markers
	%
	% find a pinhole camera model that describes each camera
	pl_to_gl_mat		= setup.pl_to_gl_mat;
	gl_plate_pos		= setup.gl_plate_pos;
	n_cameras			= setup.n_cameras;
	n_views				= setup.n_views;
	calib					= struct('P', [], 'G', [],  'R', [], 'xc', [], 'kr', [], 'ic', [], 'diag', [], 'gl_markers', [], 'ij_markers', []);
	calib(1:n_cameras)= calib;
	ij_res				= cell(1,n_cameras);
	
	for n = 1 : n_cameras
		%% load coordinates of markers from setup
		camera			= setup.camera(n);	
		[gl_markers, ij_markers] = plate_to_world(camera, setup);
		n_markers_total= size(gl_markers, 2);

		%% find best fit model
		[cal, ij_res{n}] = ...
			pinhole_fit_3d(ij_markers, gl_markers);
		
		%% transfer to structure
		calib(n).P				= cal.P;
		calib(n).G				= cal.G;
		calib(n).R				= cal.R;
		calib(n).xc				= cal.xc;
		calib(n).kr				= cal.kr;
		calib(n).ic				= cal.ic;
		calib(n).diag			= cal.diag;
		calib(n).gl_markers	= gl_markers;
		calib(n).ij_markers	= ij_markers;
	end
end
