Friday, November 15, 2024

Goat Detection and Counting Using YOLOv11

 

Goat Detection and Counting Using YOLOv11



INTRODUCTION:

YOLOv11 is a computer vision model architecture developed by Ultralytics, the creators of the YOLOv5 and YOLOv8 models. YOLOv11 supports object detection, segmentation, classification, keypoint detection, and oriented bounding box (OBB) detection

CODE 😃👇:

import cv2
from ultralytics import YOLO
from google.colab.patches import cv2_imshow

# Load the YOLOv11 model (replace ‘/content/aa.pt’ with your model path)

model = YOLO(‘/content/aa.pt’)

# Load the custom image
image_path = ‘/content/m.jpg’ # Replace with your custom image path
image = cv2.imread(image_path)

# Perform detection
results = model.predict(source=image, conf=0.1) # Set confidence threshold

# Initialize goat count
goat_count = 0

# Process each detection result
for r in results:
 for box in r.boxes:
 class_id = int(box.cls[0]) # Class ID of the detected object
 confidence = float(box.conf[0]) # Confidence score

# Check if the detection is for a goat and meets the confidence threshold
 if class_id == 0 and confidence >= 0.1: # Assuming class_id for ‘goat’ is 0
 goat_count += 1
 x1, y1, x2, y2 = map(int, box.xyxy[0]) # Bounding box coordinates
 cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
 cv2.putText(image, f”Goat: {confidence:.2f}”, (x1, y1–10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)

# Display the results
cv2.putText(image, f”Total Goats: {goat_count}”, (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
cv2_imshow(image)
cv2.waitKey(0)
cv2.destroyAllWindows()

SUPPORT ME ðŸ˜Ÿ

FREE C++ SKILLSHARE COURSE

https://skl.sh/3AUpE4C


FREE C SKILLSHARE COURSE

https://skl.sh/3Ynolmw


All Courses ðŸ˜ƒðŸ‘‡

https://linktr.ee/Freetech2024


All Products ðŸ˜ƒðŸ‘‡

https://linktr.ee/rockstararun


HP Laptop ðŸ¤©ðŸ‘‡

https://dir.indiamart.com/impcat/hp-laptop.html?utm_source=freetech-xu1ob&utm_medium=affiliate&utm_campaign=1024&utm_content=29&mTd=1

Asus Laptop ðŸ¤©ðŸ‘‡

https://www.indiamart.com/proddetail/24957009948.html?utm_source=freetech-xu1ob&utm_medium=affiliate&utm_campaign=1024&utm_content=43&mTd=1





No comments:

Post a Comment

Just ₹10 You Can Buy Online Courses

You Can Buy Online Courses With Just ₹10 – Learn New Skills at an Affordable Price! What if you could learn new technology skills without sp...