0
$\begingroup$

I have done object detection on my video data using trackers such as CSRT, KCF and got the detection part.I have ground truth coordinates (x,y) values for few frames from the original video which would be something like this.

Ground truth

this is the snapshot from the detected video

enter image description here

I have the x and y co-ords (which is x2,y2 in first image) for original video. Now I have a situation to measure the 2D distance between the ground truth and detected contact points, and for this i need to get the co-ords for the detected video. In simple words, I want to get the center value of the bounding box atleast for few frames from the detected video i.e(x1,y1) as shown in the second image.

# loop over frames from the video stream
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)

I don't know if I was clear enough to convey my problem, but please ask if anymore info is required and someone help me over here. This is so important for me. Thank you

$\endgroup$
5
  • $\begingroup$ If I understand you correctly you want to calculate the center of the bounding box retrieved from your tracking. You can simply get the coordinates of the bounding box center as follows: x_center, y_center = x + 0.5 * w, y + 0.5 * h. $\endgroup$
    – Oxbowerce
    Aug 2, 2021 at 15:38
  • $\begingroup$ thanks that worked, but is it possible to get the x,y co ordinates- as in height and width of that point with respect to frame? @Oxbowerce $\endgroup$
    – ketan
    Aug 3, 2021 at 10:23
  • $\begingroup$ What do you exactly mean with 'frame'? The code above gives you the absolute coordinates, meaning the (x, y) coordinates in the overall image relative to the image origin (probably bottom left). $\endgroup$
    – Oxbowerce
    Aug 3, 2021 at 10:30
  • $\begingroup$ @Oxbowerce lets say the video is 30 frames/sec...since i am reading each frame and placing this part in the same loop (where the frame is being read), are these (x,y) co ordinates with respect to that particular frame? $\endgroup$
    – ketan
    Aug 3, 2021 at 21:49
  • $\begingroup$ The coordinates are based on the frame that is stored in frame, the actual origin depends on the way the tracker was trained/set-up. $\endgroup$
    – Oxbowerce
    Aug 4, 2021 at 8:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.