Tyre tread analysis is a crucial task to identify wear and ensure safety, especially in vehicles that travel long distances. Using Artificial Intelligence (AI) and Python, we can automate this process quickly and accurately. Here, we show how a convolutional neural network (CNN) model, based on the VGG16 architecture, classifies tires into "new" or "used", while OpenCV helps analyze images to measure tread depth.
Technologies Used
Python:
Popular programming language for AI and Machine Learning, especially for its advanced libraries.OpenCV:
Used to process images, detect contours and measure tire tread area.TensorFlow and Keras:
Deep learning libraries. We use Keras to work with the VGG16 model, a pre-trained CNN for image recognition.Matplotlib:
Library for data visualization and graph creation, making classification results more interpretable.
Code:
1. Load and Pre-process Images:
Tire images are uploaded and resized to a standard format (150x150 pixels) required for model input. This resizing maintains the aspect ratio and normalizes pixel values between 0 and 1 to make it easier for the model to process.
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. Classification with the Trained Model:
We loaded a pre-trained convolutional neural network model, which was fine-tuned to classify tires as “new” or “used”. This model provides a confidence score that indicates the probability that a tire is new.
from tensorflow.keras.models import load_model model = load_model('pneu_classificador.keras') prediction = model.predict(image_preprocessed)
3. Contour Analysis for Groove Depth:
Groove depth detection is performed using computer vision techniques. The grayscale image goes through a blur filter and Canny edge detection, which helps identify groove contours. We then calculate the total area of the contours, which allows us to estimate wear.
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. Visualization and Analysis of Results:
After classifying and analyzing each tire, the results are displayed with Matplotlib. We compared the classification confidence score and the groove area detected in each image.
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()
This project of mine demonstrates how it is possible to automate tire wear analysis using AI and computer vision, resulting in accurate and fast classification. The VGG16 architecture and use of OpenCV are key to combining neural network model accuracy with visual sulci analysis. This system can be expanded for continuous monitoring across vehicle fleets, helping to reduce accidents and optimize tire management.
The above is the detailed content of Tire Groove Analysis with Artificial Intelligence in Python!. For more information, please follow other related articles on the PHP Chinese website!

This article explains how to use Beautiful Soup, a Python library, to parse HTML. It details common methods like find(), find_all(), select(), and get_text() for data extraction, handling of diverse HTML structures and errors, and alternatives (Sel

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

Python's statistics module provides powerful data statistical analysis capabilities to help us quickly understand the overall characteristics of data, such as biostatistics and business analysis. Instead of looking at data points one by one, just look at statistics such as mean or variance to discover trends and features in the original data that may be ignored, and compare large datasets more easily and effectively. This tutorial will explain how to calculate the mean and measure the degree of dispersion of the dataset. Unless otherwise stated, all functions in this module support the calculation of the mean() function instead of simply summing the average. Floating point numbers can also be used. import random import statistics from fracti

Serialization and deserialization of Python objects are key aspects of any non-trivial program. If you save something to a Python file, you do object serialization and deserialization if you read the configuration file, or if you respond to an HTTP request. In a sense, serialization and deserialization are the most boring things in the world. Who cares about all these formats and protocols? You want to persist or stream some Python objects and retrieve them in full at a later time. This is a great way to see the world on a conceptual level. However, on a practical level, the serialization scheme, format or protocol you choose may determine the speed, security, freedom of maintenance status, and other aspects of the program

This article compares TensorFlow and PyTorch for deep learning. It details the steps involved: data preparation, model building, training, evaluation, and deployment. Key differences between the frameworks, particularly regarding computational grap

This tutorial builds upon the previous introduction to Beautiful Soup, focusing on DOM manipulation beyond simple tree navigation. We'll explore efficient search methods and techniques for modifying HTML structure. One common DOM search method is ex

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

This article guides Python developers on building command-line interfaces (CLIs). It details using libraries like typer, click, and argparse, emphasizing input/output handling, and promoting user-friendly design patterns for improved CLI usability.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools