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?
Source of the code:
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 camera.start_preview() # 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) try: # Wait indefinitely until the user terminates the script while True: time.sleep(1) finally: camera.remove_overlay(o)
https://picamera.readthedocs.io/en/rele ... he-preview