In this paper, the importance of cost aggregation for belief propagation (BP) and the interaction of them are discussed. A global stereo matching algorithm based on BP with local edge detection-based cost aggregation is proposed. Firstly, a virtual closed edge is formed surrounding each pixel via second derivative operator in order to construct the adaptive window. Then, for centered pixel, local cost aggregation is calculated on support pixels in adaptive window. Finally, BP optimization algorithm is used to obtain the disparity. The experiments based on Middlebury benchmark indicate that local edge detection-based cost aggregation can do well with BP and also show encouraging results of proposed stereo matching algorithm.