A new solar tracking sensor based on image recognition is proposed and designed to solve the problem of low accuracy of photoelectric tracking in photovoltaic power generation. The sensor can directly output its angular deviation from the sun, and its mechanical structure and working principle are analysed in detail. We use a high-precision camera to collect the image of the two slots on the projector surface and use the Hough transform to identify the image of the light seam. After obtaining the linear equation for the two slots, the coordinate of the intersection point is found, and the calculation of the solar altitude and azimuth can be realized. We have improved the Hough transform scheme by using the skeleton image of the slots instead of the edge image. The improvement of the scheme has been proved to effectively improve the detection accuracy. A calibration test board is used to test the sensor and experimental results show that the scheme can achieve the measurement of azimuth and altitude with the accuracy of be 0.05°, which can meet the detection accuracy requirements of the solar tracking in photovoltaic power generation and many other photoelectric tracking implementations.