您好,登錄后才能下訂單哦!
這篇文章主要介紹樹莓派如何實現超聲波車牌識別系統,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
本系統使用樹莓派4B
#!/usr/bin/env python # -*- coding: utf-8 -*- from luma.core.interface.serial import i2c, spi from luma.core.render import canvas from luma.oled.device import ssd1306, ssd1325, ssd1331, sh2106 from luma.core.virtual import terminal import os import time from PIL import ImageFont from aip import AipOcr from picamera import PiCamera from time import sleep #導入 GPIO庫 import RPi.GPIO as GPIO import time #設置 GPIO 模式為 BCM GPIO.setmode(GPIO.BCM) #定義 GPIO 引腳 GPIO_TRIGGER = 27 GPIO_ECHO = 17 #設置 GPIO 的工作方式 (IN / OUT) GPIO.setwarnings(False) GPIO.setup(GPIO_TRIGGER, GPIO.OUT) GPIO.setup(GPIO_ECHO, GPIO.IN) serial = i2c(port=1, address=0x3C) device = sh2106(serial) APP_ID = 'XXX' API_KEY = 'YYY' SECRET_KEY = 'ZZZ' client = AipOcr(APP_ID, API_KEY, SECRET_KEY) def make_font(name, size): font_path = os.path.abspath(os.path.join( os.path.dirname(__file__), 'fonts', name)) return ImageFont.truetype(font_path, size, encoding="utf-8") font = make_font("/home/pi/Python/1602/msyh.ttc", 20) def distance(): # 發送高電平信號到 Trig 引腳 GPIO.output(GPIO_TRIGGER, True) # 持續 10 us time.sleep(0.00001) GPIO.output(GPIO_TRIGGER, False) start_time = time.time() stop_time = time.time() # 記錄發送超聲波的時刻1 while GPIO.input(GPIO_ECHO) == 0: start_time = time.time() # 記錄接收到返回超聲波的時刻2 while GPIO.input(GPIO_ECHO) == 1: stop_time = time.time() # 計算超聲波的往返時間 = 時刻2 - 時刻1 time_elapsed = stop_time - start_time # 聲波的速度為 343m/s, 轉化為 34300cm/s。 distance = (time_elapsed * 34300) / 2 print("距離 = {:.2f} cm".format(distance)) return distance def i2c_12864_print(x,y,text): with canvas(device) as draw: draw.text((x, y), text, fill="white", font=font) def get_file_content(filePath): with open(filePath, 'rb') as fp: return fp.read() while True: print("測量長度") csblength = distance() if csblength < 200: print("程序開始,拍攝照片") camera = PiCamera() camera.resolution = (1024, 768) camera.start_preview() camera.capture('/home/pi/Python/1602/image.jpg') camera.stop_preview() print("拍攝結束") image = get_file_content('image.jpg') result = client.licensePlate(image); print(result); carNumber = result["words_result"]["number"] i2c_12864_print(0,0,carNumber) break sleep(1)
以上是“樹莓派如何實現超聲波車牌識別系統”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。