How to use opencv image as input


I try to use that turorial on my webcam:

I want to replace image input by a video as input:

vid = cv2.VideoCapture("videoplayback.mp4")
while (True):
    ret, frame =
    cv2.imshow('frame', frame)

    run_detector_image(detector, frame)
    if cv2.waitKey(25) & 0xFF == ord('q'):

How should I modify the load_img to feed the opencv frame ?

Read the video frame by frame and convert them to JPEG format

import cv2
video = cv2.VideoCapture("videoplayback.mp4")
success,image =
count = 0
success =True
while success:
  success,image =
  cv2.imwrite("frame%d.jpg" % count, image)     # save frame as JPEG file
  count += 1