# All objects are not couting by linezone

**URL:** <https://discuss.roboflow.com/t/all-objects-are-not-couting-by-linezone/7384>\
**Category:** 🤝  Community Help\
**Created:** [October 22, 2024, 4:28am UTC](https://discuss.roboflow.com/t/all-objects-are-not-couting-by-linezone/7384 "2024-10-22T04:28:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdshihabuddinroky](https://yyz1.discourse-cdn.com/flex029/user_avatar/discuss.roboflow.com/mdshihabuddinroky/32/5731_2.png) [@mdshihabuddinroky](https://discuss.roboflow.com/u/mdshihabuddinroky)\
**Post date:** [October 22, 2024, 4:28am UTC](https://discuss.roboflow.com/t/all-objects-are-not-couting-by-linezone/7384/1 "2024-10-22T04:28:59Z")

</div>

I was facing problem that I was trying to vehicle count in cctv fotage. which was dav format. I did. I use yolo custom train model , & default model also. used bytetrack & supervision for tracking & counting. the problem is my all vehicle was not couting which are crossing line. I know there might be line axis problem but I tried with different axis of counting line. But facing problem. & my video was in dav format which was generated by cc camera. when I process my video a 5 minutes video become 600-700 mb. here I upload some process video. I compressed them. [https://drive.google.com/drive/folders/1BuGbo7\_LXGHS4EiQSF-QwVgs7EOF6Y2J?usp=sharing](https://drive.google.com/drive/folders/1BuGbo7_LXGHS4EiQSF-QwVgs7EOF6Y2J?usp=sharing)

& here is my code

‘’’

import cv2  
import supervision as sv  
from ultralytics import YOLO  
import numpy as np

# Initialize YOLO model and tracker

model = YOLO(“/content/best.pt”) # Specify your model path  
tracker = sv.ByteTrack()  
class\_names = model.names

# Annotators and line zone

bounding\_box\_annotator = sv.BoxAnnotator()  
label\_annotator = sv.LabelAnnotator()  
trace\_annotator = sv.TraceAnnotator(thickness=4)  
#start, end = sv.Point(x=75, y=479), sv.Point(x=482, y=162)  
#start, end = sv.Point(x=252, y=479), sv.Point(x=266, y=228) accurate more  
start, end = sv.Point(x=258, y=478), sv.Point(x=223, y=204)

# line\_zone = sv.LineZone(start=start, end=end)

# Initialize the LineZone for triggering

line\_zone = sv.LineZone(  
start=start, end=end  
)  
line\_zone\_annotator = sv.LineZoneAnnotator(  
thickness=4,  
text\_thickness=4,  
text\_scale=1  
)  
line\_zone\_annotator\_multiclass = sv.LineZoneAnnotatorMulticlass(  
table\_position=sv.Position.TOP\_RIGHT,  
table\_color=sv.Color.BLACK,  
text\_color=sv.Color.WHITE,  
text\_scale=0.7,  
)

# Callback function to process each frame

def process\_frame(frame: np.ndarray, index: int) → np.ndarray:  
# Perform object detection  
results = model(frame)[0]

```
# Convert results to detections and update tracker
detections = sv.Detections.from_ultralytics(results)
detections = tracker.update_with_detections(detections)

# Construct labels: Class Name and Tracker ID
labels = [
    f"{class_names[class_id]} #{tracker_id}"
    for tracker_id, class_id in zip(detections.tracker_id, detections.class_id)
]

annotated_frame = frame.copy()
annotated_frame = trace_annotator.annotate(
    scene=annotated_frame,
    detections=detections)
annotated_frame = bounding_box_annotator.annotate(
    scene=annotated_frame,
    detections=detections)
annotated_frame = label_annotator.annotate(
    scene=annotated_frame,
    detections=detections,
    labels=labels)

# Update line zone and add to frame
line_zone.trigger(detections)
annotated_frame = line_zone_annotator.annotate(annotated_frame, line_counter=line_zone)

# Annotate with multiclass counts table
annotated_frame = line_zone_annotator_multiclass.annotate(
    frame=annotated_frame, 
    line_zones=[line_zone] # List of line zones for multiclass annotator
)

return annotated_frame

```

# Process the video

sv.process\_video(  
source\_path=“/content/compressed\_input\_video.mp4”, # Add your input video path  
target\_path=“output\_video\_scale7.mp4”, # Add your output video path  
callback=process\_frame  
)

# Print results in a formatted way

print(“Line Zone Results:”)  
print(“In Count:”)  
for class\_id, count in line\_zone.in\_count\_per\_class.items():  
print(f"Class: {class\_names[class\_id]}, Count: {count}")

print(“\nOut Count:”)  
for class\_id, count in line\_zone.out\_count\_per\_class.items():  
print(f"Class: {class\_names[class\_id]}, Count: {count}")

print(“Line count in class:”, line\_zone.in\_count\_per\_class)  
print(“Line count out class:”, line\_zone.out\_count\_per\_class)

‘’’

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex029/uploads/roboflow1/original/1X/bb6edbfa56d0cf2ee603f061e9e09103502cc8cc.png) [@system](https://discuss.roboflow.com/u/system)\
**Post date:** [November 12, 2024, 4:29am UTC](https://discuss.roboflow.com/t/all-objects-are-not-couting-by-linezone/7384/2 "2024-11-12T04:29:43Z")

</div>

Closed on November 12, 2024, 4:29am UTC

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
