【问题标题】:get the upper center of bounding box opencv获取边界框opencv的上中心
【发布时间】:2020-06-11 12:52:25
【问题描述】:

代码:

# OpenCV Python program to detect cars in video frame
# import libraries of python OpenCV
import cv2
import face_recognition

# capture frames from a video
cap = cv2.VideoCapture(0)

# Initialize variables
face_locations = []

while True:
    # Grab a single frame of video
    ret, frame = cap.read()

    # Convert the image from BGR color (which OpenCV uses) to RGB color (which face_recognition uses)
    rgb_frame = frame[:, :, ::-1]

    # Find all the faces in the current frame of video
    face_locations = face_recognition.face_locations(rgb_frame)

    # Display the results
    for top, right, bottom, left in face_locations:
        # Draw a box around the face
        cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)


        cv2.circle(frame,(left, top),5,(0, 255, 0), 1)

    # Display the resulting image
    cv2.imshow('Video', frame)

    # Wait for Enter key to stop
    if cv2.waitKey(25) == 13:
        break

# Release everything if job is finished
cap.release()

这给了我,

我需要在边界框的上线中心标记黄色圆圈。我设法在左上角画了一个小圆圈,但不知道如何让它们出现在上边界框的中心。

【问题讨论】:

    标签: python opencv face-recognition


    【解决方案1】:

    如果我理解正确,我认为您可以通过更改此行来做到这一点

    cv2.circle(frame,(left, top),5,(0, 255, 0), 1)
    

    对于这一行:

    cv2.circle(frame,(int((left + right) / 2), top),5,(0, 255, 0), 1)
    

    已编辑以修复浮动错误

    【讨论】:

    • 一个小正确,将 (left + right)/2 更改为 int ((left + right) / 2) 以防止浮动错误。 :)
    猜你喜欢
    • 2023-04-04
    • 2013-01-21
    • 2021-10-20
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-14
    相关资源
    最近更新 更多