lee_w
Posts: 5
Joined: Tue Sep 05, 2017 12:25 pm

camera preview stretched at 7 inch touchscreen

Tue Sep 05, 2017 12:37 pm

Hello pi camera fellows,

I am trying to get an unstretched preview image on my touch display.
Its the official 7 inch touchscreen.
It has an non-square aspect ratio.

With the following entries at the /boot/config.txt

framebuffer_width=800
framebuffer_height=444
framebuffer_aspect=-1

The normal screen content looks good.

But the preview of the camera module seems to be directly written to the display.
The preview is always stretched.

My question is: Is it possible to stretch the preview of the camera module ?

I am using the python module: picamera

Perhaps somebody has a hint for me.

All the best,
Lee

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8716
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: camera preview stretched at 7 inch touchscreen

Tue Sep 05, 2017 1:54 pm

https://picamera.readthedocs.io/en/late ... rer.window
As the MMAL noaspect flag is not apparently set you should be able to stretch away to your hearts content.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

aBUGSworstnightmare
Posts: 1876
Joined: Tue Jun 30, 2015 1:35 pm

Re: camera preview stretched at 7 inch touchscreen

Tue Sep 05, 2017 1:58 pm

From The MagPi Camera Essentials, page 98:
Preview position/size
--preview or -p (x,y,w,h)
Allows the user to define the size of the preview window (with w
and h values) and its location on the screen (x and y). Note that this
will be superimposed over the top of any other windows/graphics.
For instance, to set its top-left corner at (100, 100) and give it
dimensions of 300 × 200, use: -p 100,100,300,200.

lee_w
Posts: 5
Joined: Tue Sep 05, 2017 12:25 pm

Re: camera preview stretched at 7 inch touchscreen

Tue Sep 05, 2017 9:11 pm

hello 6by9 and aBUGSworstnightmare,

thank you very much for the fast responses.
feels good not to be alone with this problem :-)

i already have tested the window feature with python and the picamera module.
the window option seems not to strecht the content.

i have striped down the code to this.
perhaps i did not find the right flag to avoid scaling with the default ratio.

all the best,
lee

import time

from picamera import PiCamera

camera = PiCamera()
camera.resolution = (1920,1080)

time.sleep(1)
camera.preview_fullscreen=False
camera.preview_window=(100, 100, 800, 100)
camera.start_preview(resolution=(800, 480))
time.sleep(11111)

lee_w
Posts: 5
Joined: Tue Sep 05, 2017 12:25 pm

Re: camera preview stretched at 7 inch touchscreen

Thu Sep 07, 2017 10:31 am

Hello pi cam fellows,

I also tested the terminal command:

raspistill -p 100,100,300,200

Its the same result as using python.
The preview image is cropped, but not streched.

For now i see no chance to display an unstreched image on the official 7 inch touchscreen.
Its crazy that the screen has a non squared pixel size ....

Perhaps in the future a ratio flag for the preview output of the camera would be nice.
I sthis the right place to post e feature request ?

All the best,
Lee

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

Re: camera preview stretched at 7 inch touchscreen

Thu Sep 07, 2017 11:33 am

lee_w wrote:
Thu Sep 07, 2017 10:31 am
Hello pi cam fellows,

I also tested the terminal command:

raspistill -p 100,100,300,200

Its the same result as using python.
The preview image is cropped, but not streched.

For now i see no chance to display an unstreched image on the official 7 inch touchscreen.
Its crazy that the screen has a non squared pixel size ....

Perhaps in the future a ratio flag for the preview output of the camera would be nice.
I sthis the right place to post e feature request ?

All the best,
Lee
Odd. That should definitely change the aspect, not crop. I'll try and find some time to check this today.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

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

Re: camera preview stretched at 7 inch touchscreen

Thu Sep 07, 2017 11:42 am

jamesh wrote:
Thu Sep 07, 2017 11:33 am
lee_w wrote:
Thu Sep 07, 2017 10:31 am
Hello pi cam fellows,

I also tested the terminal command:

raspistill -p 100,100,300,200

Its the same result as using python.
The preview image is cropped, but not streched.

For now i see no chance to display an unstreched image on the official 7 inch touchscreen.
Its crazy that the screen has a non squared pixel size ....

Perhaps in the future a ratio flag for the preview output of the camera would be nice.
I sthis the right place to post e feature request ?

All the best,
Lee
Odd. That should definitely change the aspect, not crop. I'll try and find some time to check this today.
Hmm, definitely cropping. I thought that used to change the aspect....will ask around.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed.
I've been saying "Mucho" to my Spanish friend a lot more lately. It means a lot to him.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8716
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: camera preview stretched at 7 inch touchscreen

Thu Sep 07, 2017 1:43 pm

jamesh wrote:
Thu Sep 07, 2017 11:42 am
Hmm, definitely cropping. I thought that used to change the aspect....will ask around.
It looks like it has always been wrong, as it is RaspiPreview setting things up incorrectly.

I was expecting to set

Code: Select all

index 7656c87..0d64408 100644
--- a/host_applications/linux/apps/raspicam/RaspiPreview.c
+++ b/host_applications/linux/apps/raspicam/RaspiPreview.c
@@ -105,12 +105,16 @@ MMAL_STATUS_T raspipreview_create(RASPIPREVIEW_PARAMETERS *state)
       preview_port = preview->input[0];
 
       MMAL_DISPLAYREGION_T param;
+      memset(&param, 0, sizeof(param));
       param.hdr.id = MMAL_PARAMETER_DISPLAYREGION;
       param.hdr.size = sizeof(MMAL_DISPLAYREGION_T);
 
       param.set = MMAL_DISPLAY_SET_LAYER;
       param.layer = PREVIEW_LAYER;
 
+      param.set |= MMAL_DISPLAY_SET_MODE;
+      param.mode = MMAL_DISPLAY_MODE_FILL;
+
       param.set |= MMAL_DISPLAY_SET_ALPHA;
       param.alpha = state->opacity;
 
@@ -121,11 +125,20 @@ MMAL_STATUS_T raspipreview_create(RASPIPREVIEW_PARAMETERS *state)
       }
       else
       {
+         param.set |= MMAL_DISPLAY_SET_NOASPECT;
+         param.noaspect = 1;
+
          param.set |= (MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN);
          param.fullscreen = 0;
          param.dest_rect = state->previewWindow;
       }
and noaspect = 1 would mean that the aspect ratio is ignored and it gets stretched (as per docs at https://github.com/raspberrypi/userland ... deo.h#L189).

OK, found. In Raspistill the camera is set to output the same resolution as the size of the preview window - https://github.com/raspberrypi/userland ... spiStill.c. Raspivid behaves as I'd expect.
Really the camera preview ought to match the aspect ratio of the capture (something I've been meaning to fix for a while), but instead it's looking at the preview window size in several places.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

lee_w
Posts: 5
Joined: Tue Sep 05, 2017 12:25 pm

Re: camera preview stretched at 7 inch touchscreen

Sat Sep 09, 2017 2:12 pm

Hello,

Found a solution for python.

GingerAdams wrote an addition "** noaspect **"
you can find it here:
https://github.com/waveform80/picamera/ ... 3667fda1c9

simply replace the 3. files at /usr/lib/python3/dist-packages/

picamera/camera.py
picamera/mmal.py
picamera/renderers.py


then this code works for me:

import time

from picamera import PiCamera

camera = PiCamera()
camera.resolution = (1920,1080)

time.sleep(1)
camera.preview_fullscreen=False
camera.preview_window=(100, 100, 800, 100)
camera.start_preview(resolution=(800, 480), noaspect=True)
time.sleep(11111)


hopefully, this will get part of the main distro of picamera.

best,
lee

Return to “Camera board”