I try to use Yolo to detect car like this code. It have no error when I use VideoCapture with mp4. when I change to RTSP it can run about 5 Second then program auto stop running . It's not show error.
cap = cv2.VideoCapture("rtsp:// url ")
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
model = models.get('yolo_nas_s', pretrained_weights="coco").to(device)
count = 0
classNames = ["car"]
limitup = [103, 161, 296, 161]
skip_frames = 3
while True:
ret, frame = cap.read()
count += 1
if ret:
detections = np.empty((0, 5))
result = list(model.predict(frame, conf=0.3))[0]
bbox_xyxys = result.prediction.bboxes_xyxy.tolist()
confidences = result.prediction.confidence
labels = result.prediction.labels.tolist()
resize_frame = cv2.resize(frame, (0, 0), fx=0.5, fy=0.5, interpolation=cv2.INTER_AREA)
cv2.imshow("Frame", frame)
if cv2.waitKey(1) & 0xFF == ord('1'):
break
else:
break
cap.release()
cv2.destroyAllWindows()
If I comment at line result = list(model.predict(frame, conf=0.3))[0]
it can run normal. How to fix this code to run by not auto stop running.