Python 中的人工智能轮胎凹槽分析!
轮胎胎面分析是识别磨损和确保安全的一项关键任务,尤其是对于长途行驶的车辆。使用人工智能 (AI) 和 Python,我们可以快速准确地自动化此过程。在这里,我们展示了基于 VGG16 架构的卷积神经网络 (CNN) 模型如何将轮胎分类为“新”或“旧”,而 OpenCV 则帮助分析图像以测量胎面深度。
使用的技术
Python:
适用于人工智能和机器学习的流行编程语言,尤其是其高级库。OpenCV:
用于处理图像、检测轮廓和测量轮胎胎面面积。TensorFlow 和 Keras:
深度学习库。我们使用 Keras 来处理 VGG16 模型,这是一个用于图像识别的预训练 CNN。Matplotlib:
用于数据可视化和图形创建的库,使分类结果更易于解释。
代码:
1。加载和预处理图像:
上传轮胎图像并将其大小调整为模型输入所需的标准格式(150x150 像素)。这种大小调整保持了纵横比,并将像素值标准化在 0 和 1 之间,以便模型更容易处理。
import cv2 import numpy as np from tensorflow.keras.applications.vgg16 import preprocess_input def process_image(image_path, target_size=(150, 150)): image = cv2.imread(image_path) if image is None: print(f"Erro ao carregar a imagem: {image_path}. Verifique o caminho e a integridade do arquivo.") return None, None image_resized = cv2.resize(image, target_size, interpolation=cv2.INTER_AREA) image_array = np.array(image_resized) / 255.0 image_array = np.expand_dims(image_array, axis=0) image_preprocessed = preprocess_input(image_array) return image_resized, image_preprocessed
2。使用训练模型进行分类:
我们加载了预先训练的卷积神经网络模型,该模型经过微调以将轮胎分类为“新”或“旧”。该模型提供了一个置信度分数,表明轮胎是新轮胎的概率。
from tensorflow.keras.models import load_model model = load_model('pneu_classificador.keras') prediction = model.predict(image_preprocessed)
3。凹槽深度轮廓分析:
使用计算机视觉技术执行凹槽深度检测。灰度图像经过模糊过滤器和 Canny 边缘检测,这有助于识别凹槽轮廓。然后我们计算轮廓的总面积,这使我们能够估计磨损。
def detect_tread_depth(image): gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray, (5, 5), 0) edges = cv2.Canny(blurred, 30, 100) contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) total_area = sum(cv2.contourArea(c) for c in contours if cv2.contourArea(c) > 100) return total_area
4。结果可视化和分析:
对每个轮胎进行分类和分析后,用 Matplotlib 显示结果。我们比较了每张图像中检测到的分类置信度得分和凹槽区域。
import matplotlib.pyplot as plt confidence_scores = [] total_area_green_values = [] predicted_classes = [] for image_file in os.listdir(ver_dir): image_path = os.path.join(ver_dir, image_file) image_resized, image_preprocessed = process_image(image_path) if image_preprocessed is not None: prediction = model.predict(image_preprocessed) confidence_score = prediction[0][0] total_area_green = detect_tread_depth(image_resized) predicted_class = "novo" if total_area_green > 500 else "usado" confidence_scores.append(confidence_score) total_area_green_values.append(total_area_green) predicted_classes.append(predicted_class) plt.imshow(cv2.cvtColor(image_resized, cv2.COLOR_BGR2RGB)) plt.title(f"Pneu {predicted_class} (Área: {total_area_green:.2f}, Confiança: {confidence_score:.2f})") plt.axis('off') plt.show() fig, axs = plt.subplots(2, 1, figsize=(10, 10)) axs[0].bar(os.listdir(ver_dir), confidence_scores, color='skyblue') axs[0].set_title('Confiança na Classificação') axs[0].set_ylim(0, 1) axs[0].tick_params(axis='x', rotation=45) axs[1].bar(os.listdir(ver_dir), total_area_green_values, color='lightgreen') axs[1].set_title('Área Verde Detectada') axs[1].tick_params(axis='x', rotation=45) plt.tight_layout() plt.show()
我的这个项目演示了如何使用人工智能和计算机视觉自动进行轮胎磨损分析,从而实现准确、快速的分类。 VGG16 架构和 OpenCV 的使用是将神经网络模型准确性与视觉脑沟分析相结合的关键。该系统可以扩展为跨车队进行持续监控,有助于减少事故并优化轮胎管理。
以上是Python 中的人工智能轮胎凹槽分析!的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

使用FiddlerEverywhere进行中间人读取时如何避免被检测到当你使用FiddlerEverywhere...

如何在10小时内教计算机小白编程基础?如果你只有10个小时来教计算机小白一些编程知识,你会选择教些什么�...

攻克Investing.com的反爬虫策略许多人尝试爬取Investing.com(https://cn.investing.com/news/latest-news)的新闻数据时,常常�...

Python3.6环境下加载pickle文件报错:ModuleNotFoundError:Nomodulenamed...

使用Scapy爬虫时管道文件无法写入的原因探讨在学习和使用Scapy爬虫进行数据持久化存储时,可能会遇到管道文�...
