The entire region of variation in the viewing range of the attitude of a workpiece is divided roughly, and images of the workpiece are captured from each direction. The images are stored together with imaging direction data as a first teaching model. Images captured by varying the imaging direction at a narrow pitch within a predetermined range of attitude variation in the workpiece are then stored together with imaging direction data as a second teaching model. Images of the workpiece are captured and compared with the teaching models. The position and attitude of the workpiece are determined by the imaging direction and imaging position of the selected teaching model.