Conventional method of counting animals is one of the most challenging tasks in livestock management; moreover, counting of animals in drone acquired imagery though promising, is more challenging in intelligent livestock management. In this paper, we apply state-of-the-art object detection model, Mask YOLOv7, for detection and counting of cattle in different scenarios such as in controlled (feedlot) environment and uncontrolled (open-range) environment. Mask mechanism was embedded into the backbone of the YOLOv7 algorithm (Mask YOLOv7) for instance segmentation of individual cattle object. We evaluate the performance of the model proposed in this study using IoU (Intersection over Union) threshold of 0.5, average precision (AP) and mean average precision (mAP). The results of the experiment conducted in this study show that the proposed model achieves an accuracy of 93% in counting cattle in controlled environment and 95% in uncontrolled environment. These results affirm the potential of the model, Mask YOLOv7, to perform competitively with any other existing object detection and instance segmentation models in terms of accuracy and average precision especially when the speed of object detection matters. Moreover, the research has potential applications in livestock inventory which helps in tracking, monitoring and reporting vital information about individual cattle.