0
$\begingroup$

I have following code for object tracking and have x and y coordinates in a dataframe for a few frames of the video. I would like to draw a line using these coordinates so that my output looks like this:

Output image

Code:

while True:

# grab the current frame, then handle if we are using a
# VideoStream or VideoCapture object
frame = vs.read()

frame = frame[1] if args.get("video", False) else frame

# check to see if we have reached the end of the stream
if frame is None:
    break

# resize the frame (so we can process it faster) and grab the
# frame dimensions
frame = imutils.resize(frame, width=720)
(H, W) = frame.shape[:2]

#init BB = initial bounding box
# check to see if we are currently tracking an object
if initBB is not None:
    # grab the new bounding box coordinates of the object
    (success, box) = tracker.update(frame)

    # check to see if the tracking was a success
    if success:
        (x, y, w, h) = [int(v) for v in box]
        cv2.rectangle(frame, (x, y), (x + w, y + h),(0, 255, 0), 2)
        if idx in range(600, 650):
           #trying to draw a line here
           cv2.line(frame, data['x2'], data['y2'], (255, 200, 0), 2)
  1. In the last line of the code I am trying to draw line on video frames using x y coordinates stored in data dataframe. But it is not working, can someone help me here so that my output looks like the uploaded image?

  2. Also, is it possible to save the detected video only for few frames. For example, the video has 10000 frames and I would like to save the output video only up to 5000 frames. Is it possible?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.