为什么OpenCV-Python在视频仪(0)中需要4到5秒才能打开相机和查看屏幕

发布于 2025-01-25 07:10:13 字数 594 浏览 4 评论 0原文

我有一个相当简单的代码,该代码检测到Cascadeclalsifier的面孔

import cv2
photo_face = cv2.VideoCapture(0)
cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
while True:
    _, frame = photo_face.read()
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = cascade.detectMultiScale(gray_frame)
    for x, y, w, h in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
    cv2.imshow('recognize_face', frame)
    if cv2.waitKey(10) == ord('q'):
        break

,但视频拍摄量大约需要4到5秒钟才能打开相机。我知道其他任何代码都不花时间,因为我尝试将其删除。我尝试在循环和级联打开时删除整个整个

I have a fairly simple code which detects faces by CascadeClassifier

import cv2
photo_face = cv2.VideoCapture(0)
cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
while True:
    _, frame = photo_face.read()
    gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = cascade.detectMultiScale(gray_frame)
    for x, y, w, h in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
    cv2.imshow('recognize_face', frame)
    if cv2.waitKey(10) == ord('q'):
        break

But the videocamera takes around 4 to 5 seconds to open the camera. I know that any other code is not taking time as I have tried removing it. I tried removing the whole while loop and cascade opening and just did a print statement after photo_face = cv2.VideoCapture(0) but even then it takes 4 to 5 seconds to print yes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文