[Python] Getting the x and y coordinates from cv2.contour in Open CV Python and store it to...

Discussão em 'Python' iniciado por Stack, Junho 27, 2025.

  1. Stack

    Stack Membro Participativo

    I'm printing the contour from cv2.findContours. It prints out something like these: [[370 269]] What i want is to get the 370 and store it into a variable.

    import cv2
    import numpy as np
    cap = cv2.VideoCapture(0)

    while True:
    _, frame = cap.read()


    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    lower = np.array([0,0,255])
    upper = np.array([255,255,255])

    imgThreshHigh = cv2.inRange(hsv, lower, upper)
    thresh = imgThreshHigh.copy()

    _,contours,_ = cv2.findContours(thresh,
    cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

    print(contours)

    cv2.imshow('frame',frame)
    cv2.imshow('Object',thresh)
    k = cv2.waitKey(5) & 0xFF
    if k == 27:
    break
    cv2.destroyAllWindows()

    Continue reading...

Compartilhe esta Página