The positioning of robots, relative to the origin of coordinates, is a crucial issue for autonomous robots. The purpose of the positioning is to find Cartesian coordinates and to position the robot body in a global coordinate system. In this paper, an image-based approach is proposed to robots positioning. In this approach, the pixels for the lines in the ground are specified in the original image. These pixels are replaced by a numerical value of zero and other pixels with a numerical value of one. The image obtained from these points is converted to an image taken from the top view using a reverse perspective transform. Then using the Hough line, the angle of the longest sequence is obtained from the zero values. This angle is used to correct changes resulting from the rotation of the image. In the next step, the information obtained is processed as a matrix containing zero and one using the Particle Swarm Optimization (PSO) algorithm and the coordinates of the location of the robot are determined from the origin. In this paper, an efficient target function is proposed for use in the PSO algorithm. The most important feature of this approach is the use of an Inverse Perspective Map (IPM) transformation to eliminate perspective effects. This method is resistant to changing the size and shape of various forms within the ground. To test the proposed method, positioning for soccer robots is used. The experiments show that the proposed approach has high accuracy in detecting the robot position. The main application of this algorithm is the positioning of airplanes and military missiles based on aerial imagery without the need for a global positioning system (GPS). It can also be used to increase the accuracy of the global positioning system.