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

One Camera, split screen render - center zoom?

Fri Dec 13, 2019 12:19 am

I have been working on a project with the V2 camera board and the Raspberry Pi 4. I need to be able create a digital zoom, and I need two identical renderers. I've got a working zoom. And I've got a working split screen. Copy of the code for both is below. I'm struggling with implementing the zoom demonstrated in the first codeblock within the second codeblock. While I keep at this on my own, I'm hoping someone else can help me. Ultimately, I need to buttons hook two buttons from GPIO to allow a user to zoom in and out.


Center Zoom

Code: Select all

from picamera import PiCamera
from picamera import Color
from time import sleep
import time
import numpy as np
import datetime as dt

camera = PiCamera()
camera.rotation = 0

camera.resolution = (3280,2464)

camera.framerate = 60  
#camera.video_stabilization = True

camera.start_preview()
camera.preview.rotation = 90

#demonstrate digital zoom
camera.zoom = (0,0,1,1)
print(camera.zoom)
steps = 100
for zf in range(0,95):
    camera.zoom = (zf/(2*steps),zf/(2*steps),1-zf/steps,1-zf/steps)
    sleep(1/steps)

#demonstrate live annotation on live preview pane
camera.annotate_text_size = 64
camera.annotate_foreground = Color('white')
camera.annotate_background = Color('black')
camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

start = dt.datetime.now()
while (dt.datetime.now() - start).seconds < 10:
    camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
camera.stop_preview()

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: 1870
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: One Camera, split screen render - center zoom?

Sun Dec 22, 2019 11:15 am

TufRat wrote:
Fri Dec 13, 2019 12:19 am
I've got a working zoom.
...
Center Zoom

Code: Select all

from picamera import PiCamera
from picamera import Color
from time import sleep
import time
import numpy as np
import datetime as dt

camera = PiCamera()
camera.rotation = 0

camera.resolution = (3280,2464)

camera.framerate = 60  
#camera.video_stabilization = True

camera.start_preview()
camera.preview.rotation = 90

#demonstrate digital zoom
camera.zoom = (0,0,1,1)
print(camera.zoom)
steps = 100
for zf in range(0,95):
    camera.zoom = (zf/(2*steps),zf/(2*steps),1-zf/steps,1-zf/steps)
    sleep(1/steps)

#demonstrate live annotation on live preview pane
camera.annotate_text_size = 64
camera.annotate_foreground = Color('white')
camera.annotate_background = Color('black')
camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')

start = dt.datetime.now()
while (dt.datetime.now() - start).seconds < 10:
    camera.annotate_text = dt.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
camera.stop_preview()
I tried your center code, did run out of resources on Pi3B with v2 camera.
So I went to mode 7 and commented out preview rotation:

Code: Select all

[email protected]:~ $ diff pic_center.orig pic_center
11c11
< camera.resolution = (3280,2464)
---
> camera.resolution = (640,480)
17c17
< camera.preview.rotation = 90
---
> #camera.preview.rotation = 90
[email protected]:~ $ 
I see what the "camera.zoom" is intended to do, but it simply does not work.
The overlayed time did increment every second.
But the whole time the same view is shown (I started "python pic_center").
Please tell how to get digital center working.

P.:S
I just remembered that I used @ethanol100's picamera zoom code back in January successfully.
Will have a look into the differences to your code:
https://www.raspberrypi.org/forums/view ... 4#p1417423
Attachments
pic_center.snapshot.png.jpg
pic_center.snapshot.png.jpg
pic_center.snapshot.png.jpg (116.49 KiB) Viewed 238 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

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

Re: One Camera, split screen render - center zoom?

Thu Jan 02, 2020 4:35 pm

I've just been running it from thonnyIDE as is. IIRC, it only works when plugged into HDMI0.

Return to “Camera board”