siemanko
siemanko

Reputation: 1409

opencv+python+linux+webcam = cannot capture frames

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?

Upvotes: 2

Views: 1521

Answers (1)

siemanko
siemanko

Reputation: 1409

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.

Upvotes: 2

Related Questions