opencv+python+linux+webcam = cannot capture frames

老子叫甜甜 提交于 2019-12-11 02:53:13

问题


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)

Any ideas?


回答1:


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

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

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



来源:https://stackoverflow.com/questions/12717743/opencvpythonlinuxwebcam-cannot-capture-frames

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!