2

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
  • I tried your code on my computer and it worked fine, so there might be something wrong with your OpenCV setup. As an aside, why don't you rather use the newer and better documented cv2 interface? Commented Oct 4, 2012 at 9:34

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.