相关疑难解决方法(0)

在脸上画出花式矩形

我使用以下代码检测面部并在面部绘制矩形.

while True:
    # get video frame
    ret, img = cap.read()

    input_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    img_h, img_w, _ = np.shape(input_img)

    detected = detector(input_img, 1)

    for i, d in enumerate(detected):
        x1, y1, x2, y2, w, h = d.left(), d.top(), d.right() + 1, d.bottom() + 1, d.width(), d.height()
        cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 0), 2)

    cv2.imshow("result", img)
    key = cv2.waitKey(30)

    if key == 27:
        break
Run Code Online (Sandbox Code Playgroud)

矩形看起来像这样:

但是我试图得到一个类似于这个的矩形:

是否有任何OpenCV或dlib函数可以帮助我获得这种有效的矩形?

python opencv image-processing dlib

7
推荐指数
1
解决办法
3937
查看次数

标签 统计

dlib ×1

image-processing ×1

opencv ×1

python ×1