import cv2
from ultralytics import solutions
cap = cv2.VideoCapture("/home/nasscom-gh-nwarch-ai/Documents/Siddharth/GSFC/GSFC_SIDD/Data_folder/172932574096445 (1).mp4")
assert cap.isOpened(), "Error reading video file"
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
# line or region points
#line_points = [(20, 400), (1580, 400)]
#best line we for our 01.mp4project
line_points = [(20, 500), (2400, 500)]
# Video writer
#video_writer = cv2.VideoWriter("object_counting_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Init Object Counter
counter = solutions.ObjectCounter(
show=False,
region=line_points,
model="/home/nasscom-gh-nwarch-ai/Documents/Siddharth/GSFC/GSFC_SIDD/inferencing/GSFC_11_5_24.pt",
#experiment
line_width = 2,
classes = [0],
up_angle=90.0,
down_angle = 270,
angle_tolerance = 30.0
)
counter.model.imgsz=[640]
# counter.model.conf =0.65
# Process video
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or video processing has been successfully completed.")
break
im0 = counter.count(im0)
#video_writer.write(im0)
cv2.line(im0, (20, 600), (2400, 600), (0,0,255), 2)
resized_frame = cv2.resize(im0, (960,640))
#cv2.line(resized_frame, (20, 500), (1500, 500), (0,0,255), 2)
cv2.imshow("Object Counting Output", resized_frame)
if cv2.waitKey(int(1000 / fps)) & 0xFF == ord("q"):
break
cap.release()
#video_writer.release()
cv2.destroyAllWindows()
suppose when i am working with some object like which move little bit in zigzag manner, so it give the wrong counting becuse when object little bit backward then it will move in the forward which result in the wrong counting