nickneubrand
Posts: 29
Joined: Fri Apr 26, 2013 4:54 am

Pygame Camera

Mon Jun 09, 2014 1:10 am

Hey Guys,

Its been a while since I have used my Raspi because the last thing I worked on involved the camera unit when there was no driver. I was wondering if there have been any developments in a driver that works with pygame? I looked all around to find out if there was, with no success. This is what I am trying to run/was trying to run about a year ago. The issue then and now seems to still be the "/dev/video0". Is there a device name that I am unaware of that will allow me to access the camera or will I have to find another way such as an alternative driver such as a UV4L? If so can you link the website for it because the last one I had is no longer working.

Code: Select all

pygame.init()
pygame.camera.init()
screen = pygame.display.set_mode([640,480])
cam = pygame.camera.Camera("/dev/video0", (640,480))
cam.start()
Thanks!
-Nick

nickneubrand
Posts: 29
Joined: Fri Apr 26, 2013 4:54 am

Re: Pygame Camera

Mon Jun 09, 2014 2:40 am

On the topic of cameras not working I tried then to stop using Pygame and just use Python

Code: Select all

import picamera
import time

with picamera.Picamera() as camera:
    camera.resolution = (640,480)
    camera.start_preview()
after running the whole sudo apt - get install python-picamera, now I just keep getting errors saying that there is "No module named picamera"

Getting really frustrated with this camera again because there is no easy way to access it through a python script. (Which is why i bought it over a year ago) and it still just gaining dust

ghans
Posts: 7878
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Pygame Camera

Mon Jun 09, 2014 9:13 am

The foundation has released the official V4L2 driver some time
ago :

http://www.raspberrypi.org/forums/viewt ... 43&t=62364

It should work with PyGame as-is , but many people are using
picamera already.

Is there a typo in your code ? The example says

Code: Select all

with picamera.PiCamera() as camera:
instead of

Code: Select all

with picamera.Picamera() as camera:
ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

nickneubrand
Posts: 29
Joined: Fri Apr 26, 2013 4:54 am

Re: Pygame Camera

Mon Jun 09, 2014 7:16 pm

Thanks for the info!

I accidentally typed in the code incorrectly when uploading.

When you say "It should work with PyGame as-is" do you mean with the name "/dev/video0" or is there a completely separate format that I am unaware of?

Also, what is the benefit of using picamera over this driver? I eventually did get picamera to work, but cannot get it within a windowed application with the camera.start_preview() . I later found out that it cannot be put in a window (as of now). So why would I want to use picamera?

ghans
Posts: 7878
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: Pygame Camera

Mon Jun 09, 2014 8:18 pm

Yes , the foundation driver creates a /dev/video0 device.
So it works directly with any V4L2-enabled piece of software ,
including PyGame.

ghans
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Return to “Camera board”