Я использую код, полученный по этой ссылке:
https://learn.adafruit.com/raspberry-pi-face-recognition-treasure-box/software
Я хочу включить распознавание лица на Raspberry Pi 3 B +.
Однако после следующего кода я получаю ошибку:
self.servo = PWM.Servo()
attributeerror: type object 'rpi.gpio.pwm' has no attribute 'Servo'
Я перепробовал множество установок GPIO и других sudo, но ничего не получилось
Код:
import cv2
import RPi.GPIO as GPIO
from RPi.GPIO import PWM
import picam
import config
import face
class Box(object):
"""Class to represent the state and encapsulate access to the hardware of
the treasure box."""
def __init__(self):
# Initialize lock servo and button.
self.servo = PWM.Servo()
GPIO.setup(config.BUTTON_PIN, RPIO.IN)
# Set initial box state.
self.button_state = GPIO.input(config.BUTTON_PIN)
self.is_locked = None
def lock(self):
"""Lock the box."""
self.servo.set_servo(config.LOCK_SERVO_PIN, config.LOCK_SERVO_LOCKED)
self.is_locked = True
def unlock(self):
"""Unlock the box."""
self.servo.set_servo(config.LOCK_SERVO_PIN, config.LOCK_SERVO_UNLOCKED)
self.is_locked = False
def is_button_up(self):
"""Return True when the box button has transitioned from down to up (i.e.
the button was pressed)."""
old_state = self.button_state
self.button_state = GPIO.input(config.BUTTON_PIN)
# Check if transition from down to up
if old_state == config.BUTTON_DOWN and self.button_state == config.BUTTON_UP:
# Wait 20 milliseconds and measure again to debounce switch.
time.sleep(20.0/1000.0)
self.button_state = GPIO.input(config.BUTTON_PIN)
if self.button_state == config.BUTTON_UP:
return True
return False