Posts: 1
Joined: Fri May 24, 2019 9:42 am

np.getbuffer(a) and memoryview(a) errors(overlay on camera preview)

Fri May 24, 2019 10:24 am

Hi everyone,

I am trying to run the code below on Raspberry Pi 3 and it shows an error that is " AttributeError: module 'numpy' has no attribute 'getbuffer' ".

If I replace 'getbuffer' with 'memoryview', it shows another error that is " UnboundLocalError: local variable 'm' referenced before assignment ".

What should I do to fix these errors?


Code: Select all

import time
import picamera
import numpy as np

# Create an array representing a 1280x720 image of
# a cross through the center of the display. The shape of
# the array must be of the form (height, width, color)
a = np.zeros((720, 1280, 3), dtype=np.uint8)
a[360, :, :] = 0xff
a[:, 640, :] = 0xff

camera = picamera.PiCamera()
camera.resolution = (1280, 720)
camera.framerate = 24
# Add the overlay directly into layer 3 with transparency;
# we can omit the size parameter of add_overlay as the
# size is the same as the camera's resolution
o = camera.add_overlay(np.getbuffer(a), layer=3, alpha=64)
    # Wait indefinitely until the user terminates the script
    while True:
Source of the code:
https://picamera.readthedocs.io/en/rele ... he-preview

Return to “Camera board”