Nowadays, image processing has become one of the widely used computer aided science. Two major branches of this scientific field are image enhancement and machine vision. Machine vision has many applications and demands in robotic and defense industries. Detecting distance of objects is one of the extensive research in the defense industry and robotic industries that a lot of annual projects have been involved in this issue both inside and outside the country. So, in this paper, an accurate algorithm is presented for measuring the distance of the objects from a camera. In this method, a laser transmitter is used alongside a regular webcam. The laser light is transmitted to the desired object and then the distance of the object is calculated using image processing methods and mathematical and geometric relations. The performance of the proposed algorithm was evaluated using MATLAB software. The accuracy rate of distance detection is up to 99.62%. The results also has shown that the presented algorithms make the obstacle distance measurement more reliable. Finally, the performance of the proposed algorithm was compared with other methods from different literatures.