In order to measure the initial gap between the workpiece and tool-cathode in electrochemical machining, the measurement method based on machine vision was studied in this paper. First, the measurement system based on machine vision was established. The hardware of the system consisted of CCD camera, image data acquisition card, light source and computer. The software of the system was developed by VC++6.0. Then, the original digital image of electrochemical machining initial gap collected by the CCD camera system was changed into the contour of image through graying, bivalency, edge detection and segmentation. Through system calibration, the physical size of the gap was calculated. Finally, relative experiments were carried out. The experimental results validated the feasibility of the method which measures the electrochemical machining initial gap based on machine vision.