Tobey
Posts: 4
Joined: Thu Mar 26, 2015 11:20 pm

Picamera stream as pygame background

Sat Mar 28, 2015 12:20 pm

I am trying to use the picam preview as my background in a pygame. I have seen it done before but by using a webcam. The code is below

Code: Select all

#cam = pygame.camera.Camera(*/dev/video0*,(640,480))
#cam.start()

#while 1:
#   image = cam.get_image()
#   screen.blit(image,0,0))
#   pygame.display.update()
#   for event in pygame.event.get():
#      if event.type == pygame.QUIT:
#         sys.exit()


I want to define cam as pygame.picamera.PiCamera()
but i dont know how to define image, as Picamera has no func. get_image()

DirkS
Posts: 10006
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Picamera stream as pygame background

Sat Mar 28, 2015 1:50 pm

Tobey wrote:I want to define cam as pygame.picamera.PiCamera()
but i dont know how to define image, as Picamera has no func. get_image()
I don't think you can do it that way, the preview is generated by the GPU and pygame does not have direct access to it.

Check out Adafruit's Pi camera tutorial at https://learn.adafruit.com/diy-wifi-ras ... -touch-cam
I think it does what you're asking for. The code for that is in the last 30 lines or so of the main module (https://github.com/adafruit/adafruit-pi ... ter/cam.py)

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

Re: Picamera stream as pygame background

Tue Jun 16, 2015 6:35 am

I hate to say, but I doubt this will ever be a possibility with PICamera. I've been trying to do the exact same thing for 2 years and it never works how I want it to. Your best bet is to just settle with a usb webcam, which I know is probably not what you want to do.

MatAff
Posts: 1
Joined: Sun Nov 20, 2016 9:04 pm

Re: Picamera stream as pygame background

Mon Nov 21, 2016 1:49 am

Have a look at this question and answer: http://stackoverflow.com/questions/2780 ... -in-pygame

Looks like the key is in staring the v4l2 (that's an l as in Llama not a one)

Code: Select all

sudo modprobe bcm2835-v4l2
I was trying this earlier today and got it to work.

Return to “Beginners”