The invention discloses a method and system for automatic detection and cleaning of dirt based on an intelligent closestool. The method includes the following steps that 1, image information of the inside of the closestool is collected, according to the collected image information of the inside of the closestool, regional division is conducted, gray-scale processing is conducted on the image information of the inside of the closestool, according to the gray-scale processing result, the dirt in the closestool is detected, and the region where the dirt is located is positioned; 2, the region where the dirt is located is cleaned through a cleaning device; 3, after cleaning is completed, the image information of the inside of the closestool is collected again, and the gray-scale processing is conducted on the image information of the inside of the closestool again; 4, according to the gray-scale processing result obtained in the step 3, whether dirt exists in the closestool or not is judged, if no, cleaning is stopped, if yes, the region where the dirt is located is positioned, and the step 2 is repeated until the gray-scale processing result obtained in the step 3 shows that no dirt exists in the closestool.