thendualism
Posts: 1
Joined: Tue Jan 08, 2019 10:59 pm

One camera, 2 preview windows. Is this possible?

Tue Feb 05, 2019 11:45 pm

I'm a total noob with this, but I have a regular RPi 3 B+ with the standard camera module. I can get the preview to work just fine with one window, but is there any way to do it such that there are two preview windows side by side? (Similar to VR output)

Here is what I have so far:
from picamera import PiCamera
from time import sleep
camera = PiCamera()
camera.resolution(640,480)
camera.preview_fullscreen = false
camera.preview_window(0,0,640,480)
camera.start_preview()
sleep(10)
camera.stop_preview()

Doub
Posts: 27
Joined: Fri Apr 07, 2017 9:48 pm

Re: One camera, 2 preview windows. Is this possible?

Wed Feb 06, 2019 10:11 am

I think the PiCamera wraps and connect the camera and renderer components. What you need is insert a splitter and add a second renderer. You probably need to go one level deeper into the MMAL binding and connect the components yourself. Maybe get the sources for the PiCamera class and modify it to suit your needs.

TufRat
Posts: 5
Joined: Wed Oct 30, 2019 8:22 pm

Re: One camera, 2 preview windows. Is this possible?

Fri Dec 13, 2019 12:07 am

I have this working, if you are still looking for a way to do this:

Code: Select all

from picamera import mmalobj as mo, mmal
from signal import pause

camera = mo.MMALCamera()
splitter = mo.MMALSplitter()
render_l = mo.MMALRenderer()
render_r = mo.MMALRenderer()

camera.outputs[0].framesize = (1080, 960)
camera.outputs[0].framerate = 30
camera.outputs[0].commit()

p = render_l.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION]
p.set = mmal.MMAL_DISPLAY_SET_FULLSCREEN | mmal.MMAL_DISPLAY_SET_DEST_RECT
p.fullscreen = False
p.dest_rect = mmal.MMAL_RECT_T(0, 0, 1080, 960)
render_l.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION] = p
p.dest_rect = mmal.MMAL_RECT_T(0, 960, 1080, 960)
render_r.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION] = p

splitter.connect(camera.outputs[0])
render_l.connect(splitter.outputs[0])
render_r.connect(splitter.outputs[1])

splitter.enable()
render_l.enable()
render_r.enable()

User avatar
HermannSW
Posts: 1768
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: One camera, 2 preview windows. Is this possible?

Wed Dec 18, 2019 9:36 am

Is there something that needs to be installed to make this work?
I started with "python pycam2preview.py" and "python3 pycam2preview.py".
Both times nothing happens, no error, just gives new command prompt,
raspivid on same Pi4B with Buster does show preview without issue.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

tvjon
Posts: 722
Joined: Mon Jan 07, 2013 9:11 am

Re: One camera, 2 preview windows. Is this possible?

Wed Dec 18, 2019 10:45 am

thendualism wrote:
Tue Feb 05, 2019 11:45 pm
...t is there any way to do it such that there are two preview windows side by side? (Similar to VR output)...
Something like this perhaps?

https://www.raspberrypi.org/forums/view ... 1&t=187070

I'm afraid I have no idea about picamera or python.

User avatar
HermannSW
Posts: 1768
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: One camera, 2 preview windows. Is this possible?

Wed Dec 18, 2019 5:15 pm

Thanks for that link.

The python script at the end of that thread contains the fix for the python script in this thread -- here final "pause()" was missing and script ended immediately. As you can see in attached raspi2png screenshot two previews on same display work, even on 7" DPMI display.

In the other thread attachment replicant.zip does contain an executable that does the same, but no source was provided.
Does anybody know where to find the C source?

I ask because I doubt that picamera can place output on different displays.
I know that "raspivid --dispnum X ..." allows for exactly that, and that is C code.
https://github.com/raspberrypi/userland ... 26f9e2535a

I would think that having a preview window on different displays connected to a single Pi would be a cool feature, eg. HDMI and DPMI on Pi3B, or HDMI0, HDMI1 and DPMI on Pi4B ...
Attachments
snapshot.dblprev.png.jpg
snapshot.dblprev.png.jpg
snapshot.dblprev.png.jpg (131.36 KiB) Viewed 443 times
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

PiGraham
Posts: 3678
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: One camera, 2 preview windows. Is this possible?

Wed Dec 18, 2019 5:22 pm

thendualism wrote:
Tue Feb 05, 2019 11:45 pm
I'm a total noob with this, but I have a regular RPi 3 B+ with the standard camera module. I can get the preview to work just fine with one window, but is there any way to do it such that there are two preview windows side by side? (Similar to VR output)
I'm curious. Why do you want to do that?

Perhaps you could make a surface twice the width of the video frame and copy the preview data to left and right halves and feed that to the display as your preview. I don't know if that would be any simpler or perform differently to running two renderers to the display.

TufRat
Posts: 5
Joined: Wed Oct 30, 2019 8:22 pm

Re: One camera, 2 preview windows. Is this possible?

Wed Dec 18, 2019 5:32 pm

What's the purpose of the "pause()"? My code was running fine without it, so I'm wondering what i missed?

Also, can anyone here help me figure out how to implement a center-tracked digital zoom? I have it working in picamera, but I don't know how to implement it in split-screen. I've posted a separated thread on this question, but it's not getting any love.

User avatar
HermannSW
Posts: 1768
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: One camera, 2 preview windows. Is this possible?

Thu Dec 19, 2019 12:14 am

TufRat wrote:
Wed Dec 18, 2019 5:32 pm
What's the purpose of the "pause()"? My code was running fine without it, so I'm wondering what i missed?
How did you execute your code?
I did "python pythonscript", and that immediately ended without displaying anything because of the missing pause().
With the "pause()" it works fine.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

User avatar
HermannSW
Posts: 1768
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: One camera, 2 preview windows. Is this possible?

Thu Dec 19, 2019 8:41 pm

HermannSW wrote:
Wed Dec 18, 2019 5:15 pm
I would think that having a preview window on different displays connected to a single Pi would be a cool feature, ...
DONE!

In below photo you can see gooseneck v2 camera mounted in WoodenBoardPi USB port, directed at its Pi3B power led.
But here the two v2 camera previews show up on two displays -- the DPI main 7" display, and the HDMI0 monitor!

The commit allowing to specify "--dispnum X" for raspivid is not available currently.
But its associated videocore changes are needed.
In order to run this demo you need to run "rpi-update" to get the latest and greatest -- you have to decide whether you take the risk.

Basically I added in script MMAL_DISPLAY_SET_NUM handling as was added to raspivid for "--dispnum X".
After "rpi-update", first run "raspivid -t 0 -dn X" for X in {0,2,3,7} and verify that you can make raspvid preview show up on different connected displays.
Then just run "python camera_preview_on_two_displays.py" (Gist has syntax highlighting):
https://gist.github.com/Hermann-SW/f100 ... 5969cd3b1c

Code: Select all

#  Live camera preview on main DPI display as well as HDMI0 monitor.
#
#  Works only after running "rpi-update" until this commit will be available:
#
#    https://github.com/raspberrypi/userland/commit/2549c149d8aa7f18ff201a1c0429cb26f9e2535a
# 
#    Values are Dispmanx display enums, therefore predominantly
#    0 = DSI/DPI LCD
#    2 = HDMI0
#    3 = SDTV
#    7 = HDMI1
#    Behaviour should the chosen display not be present should be to
#    revert to the primary display that is present.
#
#  Based on this script:
#
#    https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=232991&p=1582640#p1580053
#
from picamera import mmalobj as mo, mmal
from signal import pause

camera = mo.MMALCamera()
splitter = mo.MMALSplitter()
render_l = mo.MMALRenderer()
render_r = mo.MMALRenderer()

camera.outputs[0].framesize = (500, 500)
camera.outputs[0].framerate = 30
camera.outputs[0].commit()


p = render_l.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION]
p.set = mmal.MMAL_DISPLAY_SET_FULLSCREEN | mmal.MMAL_DISPLAY_SET_DEST_RECT | mmal.MMAL_DISPLAY_SET_NUM

#  3 = SDTV  -- not present, revert to main display (0 = DSI/DPI LCD)
p.display_num = 3 
p.fullscreen = False
p.dest_rect = mmal.MMAL_RECT_T(0, 18, 500, 500)

render_l.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION] = p


# 2 = HDMI0
p.display_num = 2
p.dest_rect = mmal.MMAL_RECT_T(512, 18, 500, 500)

render_r.inputs[0].params[mmal.MMAL_PARAMETER_DISPLAYREGION] = p


splitter.connect(camera.outputs[0])
render_l.connect(splitter.outputs[0])
render_r.connect(splitter.outputs[1])

splitter.enable()
render_l.enable()
render_r.enable()

pause()

The two previews do not look identical, because my 7" Waveshare display is rgb666 (1024x600), while the HDMI monitor is rgb888 (1920x1080):
Image


P.S:
There is way back from rpi-update -- over time or directly:
https://www.raspberrypi.org/forums/view ... 6&t=259865
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

Return to “Camera board”