How to count different objects

I have used PolygonZoneAnnotator, I need to count 4 different objects and get the individual total count. How do i find each object and get the total count of each object.

I used
zone_polygon = (ZONE_POLYGON * np.array(args.webcam_resolution)).astype(int)
zone = sv.PolygonZone(polygon=zone_polygon, frame_resolution_wh=tuple(args.webcam_resolution))
zone_annotator = sv.PolygonZoneAnnotator(

I have attached the code snippet

Based on the information provided in the extracts, you can use the process_frame() function to count the number of objects in a zone. This function uses the predictions from the YOLOv8 model to count objects in a zone and plot those zones.

Here is the code snippet from the extract:

def process_frame(frame: np.ndarray, _) -> np.ndarray:
   results = model(frame, imgsz=1280)[0]
   detections = sv.Detections.from_yolov8(results)
   detections = detections[detections.class_id == 0]

   box_annotator = sv.BoxAnnotator(thickness=4, text_thickness=4, text_scale=2)

In this code, detections.class_id == 0 is used to filter the detections for a specific class of objects. If you want to count different objects, you would need to adjust this filter to match the class IDs of the objects you want to count.

However, the extracts do not provide information on how to get the total count of different objects. You might need to modify the process_frame() function to keep track of the counts for each object type.

For more detailed instructions, you can refer to the How to Count Objects in a Zone guide on the Roboflow blog.

Hi! I’m Roboflow’s AI powered bot. This is an automated response powered using AI with knowledge from our docs, blog, and forum. If this solves your issue, please mark it as the solution using the checkbox icon. If this doesn’t solve your issue, please follow up with what you’ve tried/why, and the community will continue to chime in as usual.

How do i identify each different objects in a single polygon zone

This topic was discussed and solved in this thread, so I’ll be closing this topic