如何使用opencv显示实时视频供稿?

时间:2019-02-01 06:17:05

标签: python opencv

在尝试使用Raspberry Pi 3进行面部检测以显示坐标及其平均值时,PiCamera实时视频流仅显示静态图像,而我正在尝试获取实时视频提要。

vs = VideoStream(usePiCamera=True).start()
time.sleep(2.0)
while True:
    frame = vs.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(gray, 1.3, 5)
    detected = False
    xcoords.clear()
    for (x, y, w, h) in faces:
        detected= True
        cv2.rectangle(frame, (x, y), (x+w,y+h), (255,0,0), 2)
        coordinates = (x)
        roi_gray = gray[y:y+h, x:x+w]
        roi_color = frame[y:y+h, x:x+w]
        eyes = eyeCascade.detectMultiScale(roi_gray)
        for (ex, ey, ew, eh) in eyes:
            cv2.rectangle(roi_color, (ex,ey), (ex+ew,ey+eh), (0,255,0), 2)

    cv2.imshow('Frame', frame)
    k = cv2.waitKey(0) & 0xff
    if k == 27:
        break
vs.stop()
cv2.destroyAllWindows()

有人可以解决吗?

1 个答案:

答案 0 :(得分:0)

k = cv2.waitKey(0) & 0xff更改为k = cv2.waitKey(1) & 0xff