2

I found the following code (on http://blog.oscarliang.net/raspberry-pi-face-recognition-opencv/)

import cv

cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)

def repeat():
    global capture #declare as globals since we are assigning to them now
    global camera_index
    frame = cv.QueryFrame(capture)
    cv.ShowImage("w1", frame)
    c = cv.WaitKey(10)
    if(c=="n"): #in "n" key is pressed while the popup window is in focus
        camera_index += 1 #try the next camera index
        capture = cv.CaptureFromCAM(camera_index)
        if not capture: #if the next camera index didn't work, reset to 0.
            camera_index = 0
            capture = cv.CaptureFromCAM(camera_index)

while True:
    repeat()

The code compiles great when I ran it via the terminal, but there is no video feed. The camera's red light doesn't turn on (I am using Rasp Pi's camera). I get the following warning:

GLib -GObject-WARNING **: Attempt to add property GtkSettings::gtk-label-select-on-focus after class was initialised.

I did try using the camera via the python terminal -- i.e., using raspistill -- and the camera works. I followed http://www.raspberrypi.org/documentation/usage/camera/python/README.md Do I need to amend the code below with import picameraetc?

Can anyone please help me with this?

Thanks!

  • Hei, can you confirm that you have /dev/video0 ? – musr Jul 8 '16 at 6:35
5

OpenCV uses V4L to communicate with web-cams by default. When using the Pi's camera module this means you need to load a V4L driver to expose the camera module as a V4L device (like /dev/video0). This forum post contains details of the foundation's official V4L driver but the short version is:

  • Use sudo rpi-update to update your firmware (the driver is part of the firmware)
  • Use sudo reboot to reboot the Pi
  • After rebooting, use sudo modprobe bcm2835-v4l2 to load the V4L driver

At this point you should find /dev/video0 exists and OpenCV should be able to use the Pi's camera module. Control of the camera module (via the V4L driver) requires the v4l2-ctl utility. Details for installing this are in the linked forum post.

  • Thanks for your reply. I still could not get the feed to come in the dialog box..I did compile openCv properly, did the update...can you please tell me what else I can try?. – user2457324 Oct 30 '14 at 23:01
  • the red light on the camera doesn't appear at all..it does work with raspistill etc. – user2457324 Oct 30 '14 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.