A new improved Kernel Density Estimation (KDE) algorithm used to segment foreground was proposed for the problem of reciprocating pumps and other troubles for segmenting foreground in the field of Coal Bed Methane (CBM) extraction and poor real-time of KDE. Background Subtraction (BS) and three frame difference were applied to divide the image into dynamic and non-dynamic background regions and then KDE was used to segment foreground for the dynamic background region. A new method of determining dynamic threshold was proposed when segmenting foreground region. Mean absolute deviation over the sample and sample variance were combined to compute the bandwidth. And the strategy of combining regular update with real-time update was used to renew the second background model. Random selection strategy instead of First In First Out (FIFO) mode was applied when replacing samples of the second background model. In the simulation experiments, the average time-consuming of per frame image is reduced by 94.18% and 15.38% and moving objects are more complete when comparing the improved KDE with the KDE and Background Subtraction Kernel Density Estimation (BS-KDE) respectively. The experimental results show that the proposed algorithm can detect foreground in the field of CBM extraction accurately and meet the real-time requirement in the standard definition video surveillance system basically.