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

Camera Preiview in Window

Wed Feb 11, 2015 7:39 am

Hi I had a question and was wondering if anyone could help me. This is about a 2 year old question that I have not had any luck with and I was hoping that now that the RPi2 has come out maybe I can accomplish this project.

I'm looking to take the RPi camera stream and put it in a window via python preferably with pygame. I wanted the resolution to be twice that size of the window. Lastly when the arrow keys are pressed I want the streaming video to move around by 1 pixel in the corresponding direction. I want to do all of this on the Pi and put it out directly on my HDMI screen without using servers or networks.

Again I tried this about 2 years ago with the UV4L driver, which didn't work for this. Plus I cant get it to work on the RPi2 currently. I then also looked into seeing if this could be done with the picamera "pure python camera interface" and to my knowledge it cant.

Does anyone have any pointers to help me with this. It's a really simple goal, and I don't know why the picamera struggles with it so much. If I use a USB camera, this is super easy and works because I can access the /dev/video0, but has terrible fps when I tried on the Model B. Maybe the Pi2 could handle it better.

Any help would be appreciated

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

Re: Camera Preiview in Window

Wed Feb 11, 2015 8:11 am

Try this on your old Pi:

Code: Select all

sudo apt-get update
sudo apt-get install guvcview v4l2-utils
sudo modprobe bcm2835-v4l2
guvcview &
The problem with the raspistill/raspicam preview is that it
is hardware-acclerated. It runs completely independent of
the X window system and both the camera apps and Xorg
have no idea that the other one exists. You have to
manually synchronise them.

Example code might be found by taking apart omxplayerGUI ,
which is bundled with Minimal Kiosk Browser (kweb).

Additionally you can use v4l2-ctl to tune the official camera
driver for use with omxplayerGUI and guvcview :

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

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: Camera Preiview in Window

Thu Feb 12, 2015 1:29 am

Unfortunately, these things didn't really work. Though, I think that a lot of it was above my level of understanding, so I probably did it wrong. I'll probably just go back to using a USB camera. I still just find it amazing that after 2 years of the camera board being out, its still ridiculously hard to use it in combination with a windowed application.

Thanks though,
-Nick

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

Re: Camera Preiview in Window

Thu Feb 12, 2015 6:17 am

The commands i posted , did they give any error
messages ? Note that you propably need to
unload unofficial drivers like u4vl first.


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: Camera Preiview in Window

Thu Feb 12, 2015 8:40 pm

I continued to get module errors in shell (because I am using pygame), so I'm not actually using raspistill/raspicam preview.

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

Re: Camera Preiview in Window

Fri Feb 13, 2015 11:52 am

Please post both your actual code and
the corresponding error messages.

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

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 24198
Joined: Sat Jul 30, 2011 7:41 pm

Re: Camera Preiview in Window

Fri Feb 13, 2015 1:26 pm

nickneubrand wrote:Unfortunately, these things didn't really work. Though, I think that a lot of it was above my level of understanding, so I probably did it wrong. I'll probably just go back to using a USB camera. I still just find it amazing that after 2 years of the camera board being out, its still ridiculously hard to use it in combination with a windowed application.

Thanks though,
-Nick
It's because the preview is not accessible to X windows - it's composited at a very low level by the GPU. This is for performance reasons. It would be possible to have the preview in a window, as long as you didn't mind a massive performance hit. Which may not be so bad now we have the B2, but would be useless on the B/B+.

You can of course specify exactly where on the screen the preview appears and what size, so if you know where the window is, you can put it on top of it, but that goes wrong when you have another window overlapping. I've seen exactly the same issue when playing back video on PC's where the GPU was doing the decoding/viewing.

Weston/Wayland may help in this regard, as I believe that uses dispmanx compositing which is what the preview uses.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

ethanol100
Posts: 587
Joined: Wed Oct 02, 2013 12:28 pm

Re: Camera Preiview in Window

Fri Feb 13, 2015 2:22 pm

nickneubrand wrote: I'm looking to take the RPi camera stream and put it in a window via python preferably with pygame. I wanted the resolution to be twice that size of the window. Lastly when the arrow keys are pressed I want the streaming video to move around by 1 pixel in the corresponding direction. I want to do all of this on the Pi and put it out directly on my HDMI screen without using servers or networks.
No problem, should be easy. Look for example here: https://github.com/adafruit/adafruit-pi-cam
They use the python picamera library together with pygame, this has several advantages over using the v4l2 module.

The concept of display only a quarter of image is not very effective, you will get better results if you use the zoom function of python picamera http://picamera.readthedocs.org/en/late ... amera.zoom.
Have you ever googled or tried something instead of only blaming the RaspberryPi camera?
Again I tried this about 2 years ago with the UV4L driver, which didn't work for this. Plus I cant get it to work on the RPi2 currently. I then also looked into seeing if this could be done with the picamera "pure python camera interface" and to my knowledge it cant.
Only saying "didn't work for this" is not very productive, provide some more hints! And then you can get some help.
Does anyone have any pointers to help me with this. It's a really simple goal, and I don't know why the picamera struggles with it so much. If I use a USB camera, this is super easy and works because I can access the /dev/video0, but has terrible fps when I tried on the Model B. Maybe the Pi2 could handle it better.
If you not explain, why you can't access /dev/video0 for the pi camera, we can't help either. But you should not expect more then a few frames if you do not use any hardware acceleration. And it is a simple goal, for low frame rates, but for higher frame rates this is not any more a simple goal. So it would help, if you could explain more accurately what you want to achieve.

Return to “Camera board”