In computer numerical control machine tools, using machining simulation to prevent collision becomes more and more popular due to its efficiency and low cost. However, if the entire digital model of the machining setup does not exist, the simulation is not applicable. As a result, the operator has to manually check the numerical control program, which is a time-consuming and error-prone process. In this paper, an on-machine vision system is presented to quickly construct the digital model based on the actual machining setup. The total construction for a complex setup can be done within a few minutes. Several key technologies have been developed. First, a 2D edge feature detection algorithm has been designed which will extract the edges of the object of interest by processing both the real and virtual images. Second, a stereo vision system is developed which will obtain the three-dimensional (3D) edge data of the object of interest. A new algorithm is presented to solve correspondence, which is the key problem of the stereovision system. Furthermore, the 3D object recognition algorithm is developed to let the system intelligently search for the matched solid model in the database and import it into the virtual environment with an accurate pose. Finally, experiments are carried out to test the developed system.