The invention relates to a method for optically determining the position and/or orientation of an object in space on the basis of images from at least one camera (24a, 24b). At least one 2D image of the object is recorded; 2D contour information is extracted from the image. On the basis of the contour information, at least one area (40) of the object is determined. Furthermore, 3D information is obtained from the at least one 2D image or a further 2D image. A portion situated within the determined area (40) of the object is selected from this 3D information. The position and/or orientation of the object is then determined on the basis of the selected portion of the 3D information. The invention furthermore relates to a use of the method, a device for carrying out the method and a milking robot with such a device.