Traditional sheep counting methods are labour-intensive, time-consuming, and potentially disruptive to sheep behaviour. Unmanned aerial vehicles (UAVs) and machine learning (ML) techniques have emerged to address these challenges by automating the process. However, these solutions face difficulties due to low object-to-image-pixel ratios and high object densities in images captured for sheep counting, which can compromise detection and counting accuracy. In this study, we introduce and evaluate a novel approach, sub-window inference, designed to increase the object-to-image-pixel ratios, thereby enhancing the performance of existing object detection and segmentation models. Our method was compared to four other object counting techniques, demonstrating superior performance in terms of a reduced mean absolute error (MAE) of 3.21 sheep and a mean absolute percentage error (MAPE) of 1.27%. Furthermore, our findings indicate that incorporating random cropping data augmentation during model training significantly enhances both detection and counting accuracy. It is important to note that a limitation of sub-window inference is that it does not facilitate real-time count predictions. Overall, our proposed method of sub-window inference reduces the MAE in automated sheep counting techniques involving UAVs and ML, presenting a highly effective solution that benefits sheep farmers.