1

I want to display picamera's preview on fb1 in raspberry pi 4.

My environment is 64-bit aarch64 self compiled system. use vc4-fkms-v3d dtoverlay.

It seems that the preview image was direct draw on fb0 by GPU, someone suggest rpi-fbcp, but it can't be compile on rpi4 due to lack dispmanx api.

so I use python to implement a similar program, numpy.memmap open fb0, grab data, then write to fb1. it works and very fast! I can saw mouse point track was mirrored in realtime, even spinning gears of glxgear, but no luck with picamera's preview screen.

the picamera's preview was live in fb0 and overlay everything, I can mirror everything below it.

how to access the picamera's preview data? it shows on screen, but did not leave any footprint in fb0.

python code:

import numpy as np
fb0 = np.memmap('/dev/fb0', dtype='uint8',mode='r+', shape=(480,800,4))
fb1 = np.memmap('/dev/fb1', dtype='uint8',mode='r+', shape=(240,240,2))
img0 = fb0[0:240, 0:240]
img1 = BGRAtoBGR565(img0)
fb1[0:240,0:240] = img1

to produce preview image

from picamera import PiCamera
camera = PiCamera()
camera.start_preview(fullscreen=False,window=(0,0,240, 240))

I have tried python-mss, only grab image below preview screen too.

I have tested mmalobj follow the tutorial to draw a crosshair on preview, it's so lag and throws many exceptions.

picamera.exc.PiCameraMMALError: no buffers available: Resource temporarily unavailable; try again later
Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 232, in 'calling callback function'
  File "/home/pi/.local/lib/python3.7/site-packages/picamera/mmalobj.py", line 1227, in wrapper
    self._pool.send_buffer(block=False)
  File "/home/pi/.local/lib/python3.7/site-packages/picamera/mmalobj.py", line 1931, in send_buffer
    super(MMALPortPool, self).send_buffer(port, block, timeout)
  File "/home/pi/.local/lib/python3.7/site-packages/picamera/mmalobj.py", line 1881, in send_buffer
    raise PiCameraMMALError(mmal.MMAL_EAGAIN, 'no buffers available')

It seems picamera's preview draws on screen directly and does not via /dev/fb0. I have found another project py-videocore6 which can access GPU memory, but I don't know where to grap video data.

Mouse
  • 111
  • 1
  • 7
  • Is your question about C++ and how to compile `dispmanx`? Or is it about Python but not showing any Python code? What code are you using to run the camera? – Mark Setchell Oct 28 '20 at 17:49
  • I want to know how got preview data in python, so I can display it on another place and add some overlay on it. – Mouse Oct 28 '20 at 18:10
  • Why are you showing error messages from C++ compiler? Your question is about Python, surely? Please put all the `import` statements back in your Python so it runs as a proper MCVE. Please also show the commands you are using to control the camera. – Mark Setchell Oct 28 '20 at 18:11
  • Where's the code for `BGRAtoBGR565()` please? Why are the 2 framebuffers in different formats please? – Mark Setchell Oct 28 '20 at 18:15
  • My code distributed to many classes and files, and many reference packages. to simplify the question, I just write the core logic code. the implement of BGRAtoBGR565 and why 2 framebuffers in different format does not affect the question and the potential answer. I can skip this function and make 2 fb's format equally. the question is why preview image does not in /dev/fb0 – Mouse Oct 28 '20 at 18:18
  • This seems to compile fine with `dispmanx` on my RaspberryPI 4 https://github.com/AndrewFromMelbourne/raspi2fb/ – Mark Setchell Oct 29 '20 at 09:28
  • What's arch of your Raspberry-pi4, I am running 64bit aarch64. – Mouse Oct 29 '20 at 16:24
  • I am on armv7, i.e. 32-bit. – Mark Setchell Oct 29 '20 at 16:34
  • Alright, I must declare my environment for stuck question. – Mouse Oct 29 '20 at 16:41

0 Answers0