本文介绍了opencv+python+linux+webcam = 无法捕捉帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 opencv 在 python 中编写简单的人脸检测.但不幸的是,我的 opencv 拒绝检测我的网络摄像头.我不确定它在内部是如何工作的,因为文档非常有限,但 CaptureFromCAM(-1) 返回一些对象,但 QueryFrame 不返回.例如,当我尝试在奶酪中使用我的两个相机中的一个时,我可以毫无问题地获得视频.

I am trying to code up simple face detection in python using opencv. But unfortunately my opencv is refusing to detect my webcam. I am not sure how it works internally, as documentation is very limited, but CaptureFromCAM(-1) returns some object, but QueryFrame returns nones. When I try to use one of my two cameras for example in cheese, I get video without a problem.

    capture = cv.CaptureFromCAM(-1)
    faceCascade = cv.Load("haarcascade_frontalface_alt.xml")
    while (cv.WaitKey(15)==-1):
        img = cv.QueryFrame(capture)
        if img != None:
          image = DetectFace(img, faceCascade)
          cv.ShowImage("face detection test", image)

    cv.ReleaseCapture(capture)

有什么想法吗?

推荐答案

好的,我想通了.基本上我的 openvc 是用 v4l(Linux 视频)支持编译的.

Ok, I have figured it out. Basically my openvc was compiled with v4l (video for linux) support.

在解决此问题时,您首先需要确保您的相机与其他使用 v4l 的应用程序一起工作.如果是这种情况,那么您可以尝试使用 v4l 支持重新编译 openvc.对于 gentoo(使用 portage),它非常简单:

When solving this problem you first need to make sure your camera is working with some other application using v4l. If that is the case then you can try to recompile openvc with v4l support. For gentoo (which uses portage) it is very simple:

    sudo su
    USE="v4l v4l2" emerge -av opencv

对于其他包管理器,要么找出一些东西,要么使用 USE_V4L=ON 从源代码编译.

for other package managers either figure something out or compile from source with USE_V4L=ON.

这篇关于opencv+python+linux+webcam = 无法捕捉帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 22:08