I'm trying to count the number of cars visible in a frame. Here is an excerpt:
while True:
# Read frame from video
ret, frame = cv2.VideoCapture(input_video).read()
if not ret:
break
# Detect objects in the frame using Darknet
darknet_output = proc.stdout.readline().decode()
if darknet_output.startswith("Enter Image Path:"):
darknet_output = proc.stdout.readline().decode()
objects = []
while darknet_output.strip() != "":
objects.append(darknet_output.strip())
darknet_output = proc.stdout.readline().decode()
# Count the number of cars detected in the frame
car_count = 0
for obj in objects:
obj_class, obj_confidence, (x, y, w, h) = obj.split()
if obj_class == "car":
car_count += 1
# Draw text on the top of the frame with the car count
cv2.putText(frame, "Cars: {}".format(car_count), org, font, font_scale, color, thickness, cv2.LINE_AA)
# Display the frame with the car count
cv2.imshow("frame", frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
The error that I'm having is
line 54, in module obj_class, obj_confidence, (x,y,w,h) = obj.split() ValueError: not enough values to unpack ( expected 3, got 1)
The main goal I'm trying to achieve is output a value on top of the screen of car objects. Is there a better way to do this?