The invention discloses a Canny operator-based foam boundary recognition and grain size analysis method, which is characterized by comprising the following steps of: after calling an image, selecting between circular foam recognition and noncircular foam recognition according to the state of foams; graying an original drawing in the circular foam recognition; then, on one hand, performing logarithmic enhancement and critical binarization processing on a gray-scale drawing, on the other hand, introducing a Canny operator to recognize foam boundary in the gray-scale drawing and performing expansion processing, and finally superposing the two drawings and connecting lines of the foam boundary; performing Laplace enhancement processing on the original drawing in the noncircular foam recognition, introducing the Canny operator to extract the boundary of the foam, recognizing an identification mark step by step by repeatedly using corrosion, scanning, segmentation and filling and finally connecting the lines of the foam boundary; and finally obtaining a grain size analysis report. According to the method, the foams with small boundary and background contrast can be recognized, the calculation complexity is low, and the speed is high; and the method is suitable for objects such as fire extinguishing foams, floatation foams and well drilling foams.