搜索
首页后端开发Python教程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()

Análise de Sulco de Pneus com Inteligência Artificial em Python!

Análise de Sulco de Pneus com Inteligência Artificial em Python!

Análise de Sulco de Pneus com Inteligência Artificial em Python!

我的这个项目演示了如何使用人工智能和计算机视觉自动进行轮胎磨损分析,从而实现准确、快速的分类。 VGG16 架构和 OpenCV 的使用是将神经网络模型准确性与视觉脑沟分析相结合的关键。该系统可以扩展为跨车队进行持续监控,有助于减少事故并优化轮胎管理。

以上是Python 中的人工智能轮胎凹槽分析!的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
列表和阵列之间的选择如何影响涉及大型数据集的Python应用程序的整体性能?列表和阵列之间的选择如何影响涉及大型数据集的Python应用程序的整体性能?May 03, 2025 am 12:11 AM

ForhandlinglargedatasetsinPython,useNumPyarraysforbetterperformance.1)NumPyarraysarememory-efficientandfasterfornumericaloperations.2)Avoidunnecessarytypeconversions.3)Leveragevectorizationforreducedtimecomplexity.4)Managememoryusagewithefficientdata

说明如何将内存分配给Python中的列表与数组。说明如何将内存分配给Python中的列表与数组。May 03, 2025 am 12:10 AM

Inpython,ListSusedynamicMemoryAllocationWithOver-Asalose,而alenumpyArraySallaySallocateFixedMemory.1)listssallocatemoremoremoremorythanneededinentientary上,respizeTized.2)numpyarsallaysallaysallocateAllocateAllocateAlcocateExactMemoryForements,OfferingPrediCtableSageButlessemageButlesseflextlessibility。

您如何在Python数组中指定元素的数据类型?您如何在Python数组中指定元素的数据类型?May 03, 2025 am 12:06 AM

Inpython,YouCansspecthedatatAtatatPeyFelemereModeRernSpant.1)Usenpynernrump.1)Usenpynyp.dloatp.dloatp.ploatm64,formor professisconsiscontrolatatypes。

什么是Numpy,为什么对于Python中的数值计算很重要?什么是Numpy,为什么对于Python中的数值计算很重要?May 03, 2025 am 12:03 AM

NumPyisessentialfornumericalcomputinginPythonduetoitsspeed,memoryefficiency,andcomprehensivemathematicalfunctions.1)It'sfastbecauseitperformsoperationsinC.2)NumPyarraysaremorememory-efficientthanPythonlists.3)Itoffersawiderangeofmathematicaloperation

讨论'连续内存分配”的概念及其对数组的重要性。讨论'连续内存分配”的概念及其对数组的重要性。May 03, 2025 am 12:01 AM

Contiguousmemoryallocationiscrucialforarraysbecauseitallowsforefficientandfastelementaccess.1)Itenablesconstanttimeaccess,O(1),duetodirectaddresscalculation.2)Itimprovescacheefficiencybyallowingmultipleelementfetchespercacheline.3)Itsimplifiesmemorym

您如何切成python列表?您如何切成python列表?May 02, 2025 am 12:14 AM

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

在Numpy阵列上可以执行哪些常见操作?在Numpy阵列上可以执行哪些常见操作?May 02, 2025 am 12:09 AM

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,减法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Python的数据分析中如何使用阵列?Python的数据分析中如何使用阵列?May 02, 2025 am 12:09 AM

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

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

热工具

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器