树莓派如何实现超声波车牌识别系统
这篇文章主要介绍树莓派如何实现超声波车牌识别系统,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的休宁县网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
树莓派车牌识别系统
本系统使用树莓派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)
以上是“树莓派如何实现超声波车牌识别系统”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
网站题目:树莓派如何实现超声波车牌识别系统
文章地址:http://myzitong.com/article/godsog.html