A method of calibrating a three-dimensional time-of-flight imaging system in a three-dimensional environment, the method comprising the steps of: a) determining a reference orthogonal virtual three-dimensional coordinate system (M c) for the three-dimensional imaging system, the reference orthogonal virtual three-dimensional coordinate system (M c) having horizontal, vertical and depth axes in which the horizontal axis and the vertical axis are respectively aligned with the horizontal and vertical axes of a sensor in the three-dimensional imaging system with the depth axis being orthonormal to the plane of the sensor defined by its horizontal and vertical axes; b) obtaining a vertical direction (V w) of the real world in the virtual coordinate system (M c); c) determining with respect to the reference coordinate system a real world three-dimensional orthonormal coordinate system (M w) having horizontal, vertical and depth axes in which the vertical axis is rotated to align it with respect to the vertical direction (V w); d) determining a point in the scene as a new origin for the real world three-dimensional orthonormal coordinate system (M w); e) deriving a translation vector (T v) from the origin of the virtual three-dimensional coordinate system (M c) to the point defined as the new origin of the scene; f) deriving a rotation matrix (M r) for transforming the virtual three-dimensional coordinate system into the real world three-dimensional coordinate system; and g) deriving a calibration matrix (M c2w) for the three-dimensional imaging system as the rotation matrix translated by the translation vector; characterised in that the method further comprises the steps of:- h) aligning a plane defined by the vertical and depth axes of the real world three-dimensional coordinate system to be coplanar with a plane defined by the virtual vertical axis and the virtual depth axis of the virtual three-dimensional coordinate system (M c); and i) automatically refining the calibration matrix (M c2w) if changes are detected in at least one of: the position and the orientation of the three-dimensional imaging system with respect to the three-dimensional environment. a) determining a reference orthogonal virtual three-dimensional coordinate system (M c) for the three-dimensional imaging system, the reference orthogonal virtual three-dimensional coordinate system (M c) having horizontal, vertical and depth axes in which the horizontal axis and the vertical axis are respectively aligned with the horizontal and vertical axes of a sensor in the three-dimensional imaging system with the depth axis being orthonormal to the plane of the sensor defined by its horizontal and vertical axes; b) obtaining a vertical direction (V w) of the real world in the virtual coordinate system (M c); c) determining with respect to the reference coordinate system a real world three-dimensional orthonormal coordinate system (M w) having horizontal, vertical and depth axes in which the vertical axis is rotated to align it with respect to the vertical direction (V w); d) determining a point in the scene as a new origin for the real world three-dimensional orthonormal coordinate system (M w); e) deriving a translation vector (T v) from the origin of the virtual three-dimensional coordinate system (M c) to the point defined as the new origin of the scene; f) deriving a rotation matrix (M r) for transforming the virtual three-dimensional coordinate system into the real world three-dimensional coordinate system; and g) deriving a calibration matrix (M c2w) for the three-dimensional imaging system as the rotation matrix translated by the translation vector; characterised in that the method further comprises the steps of:- h) aligning a plane defined by the vertical and depth axes of the real world three-dimensional coordinate system to be coplanar with a plane defined by the virtual vertical axis and the virtual depth axis of the virtual three-dimensional coordinate system (M c); and i) automatically refining the calibration matrix (M c2w) if changes are detected in at least one of: the position and the orientation of the three-dimensional imaging system with respect to the three-dimensional environment. h) aligning a plane defined by the vertical and depth axes of the real world three-dimensional coordinate system to be coplanar with a plane defined by the virtual vertical axis and the virtual depth axis of the virtual three-dimensional coordinate system (M c); and i) automatically refining the calibration matrix (M c2w) if changes are detected in at least one of: the position and the orientation of the three-dimensional imaging system with respect to the three-dimensional environment.