0

On a Raspberry Pi with a camera module. I'm grabbing the output from the camera OK and blitting it to a surface and that's fine. The problem is, when I call start() on the camera, it is creating a small borderless extra window in the screen with the contents of the camera. I haven't been able to see anywhere to request that this not occur and it seems that the start() is pretty essential. The code is pretty unexciting. How do I hide or disable this buffer?

import pygame
import pygame.camera
from pygame.locals import *
import time

pygame.init()
pygame.camera.init()


size1=(1920,1080)
size2=(640,480)
cam = pygame.camera.Camera("/dev/video0",size2)
cam.start()
display = pygame.display.set_mode(size2, 0)
snapshot = pygame.surface.Surface(size2, 0, display)
while True:
  snapshot = cam.get_image(snapshot)
  display.blit(snapshot,(0,0))
  pygame.display.flip()
  time.sleep(10)

It actually was perplexing me for a while because I had missed out the flip() and I thought I was just getting the image in a small size with a black border. This is running with X and not on a bare console.

As a bonus, the get_image() images have a weird color quality even though the one in the small buffer window looks a lot closer to the real colors (I've tried requesting RGB but it's exactly the same).

Additional info: Having VNCed in, this buffer is not showing in the VNC client so it seems it has something to do with the framebuffer or something?

Richard Thomas
  • 350
  • 1
  • 10
  • what system do you use? It works on Linux Mint 19.3 with standard GUI without problem. – furas Feb 11 '20 at 00:35
  • It's a Raspbian. 9.1 Additionally, it's a Pi Zero W. I may grab one of its bigger brothers to check that. – Richard Thomas Feb 11 '20 at 00:48
  • Raspberry has special Python's module for camera - [picamera](https://picamera.readthedocs.io/). Maybe it will work better. It can return image as [numpy array](https://picamera.readthedocs.io/en/release-1.13/recipes2.html), and `PyGame` has [make_surface](https://www.pygame.org/docs/ref/surfarray.html#pygame.surfarray.make_surface) to convert numpy array to `Surface` – furas Feb 11 '20 at 01:00
  • see also [Display IO Stream from Raspberry Pi Camera as video in PyGame](https://stackoverflow.com/questions/27805077/display-io-stream-from-raspberry-pi-camera-as-video-in-pygame) – furas Feb 11 '20 at 01:10
  • @furas, thanks. I may try that. I was thinking I might use some pygame features so that is why I went there first. I may not need them though. – Richard Thomas Feb 11 '20 at 02:44

1 Answers1

0

I attempted a full-upgrade and the Pi wouldn't boot so I rescued my files and went with a fresh install. It's working fine now. No extra window and the colors are good. I'm not sure what the root cause was but consider this done now.

Richard Thomas
  • 350
  • 1
  • 10