+
95
-

python如何对摄像头实时绿幕抠图换背景?

python如何对摄像头实时绿幕抠图换背景?


网友回复

+
15
-

# -*- coding: utf-8 -*-
from PIL import Image
import numpy as np
import cv2

cap =cv2.VideoCapture(0,cv2.CAP_DSHOW)
cap.set(5,10)

# 要替换的背景,分辨率为摄像头的尺寸,否则会报错
img_back=cv2.imread('bk.jpg')


while True:
    ret,frame = cap.read()
    if ret == False:
        continue
    #获取摄像头捕获相片的尺寸,替换背景图片尺寸必须与摄像头图片尺寸一致,否则会报错
    rows, cols, channels = frame.shape
    print(frame.shape)

    lower_color =...

点击查看剩余70%

我知道答案,我要回答