In recent years there have been many proposals for automated applications in vegetable harvesting. There are two major challenges: estimation of yield and harvesting of fruit trees. This research proposes a new algorithm that allows accurate counting of the number of fruits on a tree to accurately estimate the output of a dragon fruit. The algorithm consists of the following main steps: image segmentation, boundary determination, shape analysis, and overlap analysis to count the number of dragon fruits per tree. Experimental results show that the algorithm can solve the problem of counting the correct number of fruits per tree to accurately estimate the yield of dragon fruit in the farm.