Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
11 views22 pages

Nan Mudhalvan Manual

The document outlines a project aimed at developing an automated vehicle number plate detection system using Python, OpenCV, and Streamlit, addressing inefficiencies in manual identification. It details the approach, including data collection, preprocessing, model training, and deployment, alongside various business use cases such as traffic management and law enforcement. Additionally, it discusses the integration of a user-friendly web application for real-time detection and performance evaluation metrics.

Uploaded by

Praveen Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views22 pages

Nan Mudhalvan Manual

The document outlines a project aimed at developing an automated vehicle number plate detection system using Python, OpenCV, and Streamlit, addressing inefficiencies in manual identification. It details the approach, including data collection, preprocessing, model training, and deployment, alongside various business use cases such as traffic management and law enforcement. Additionally, it discusses the integration of a user-friendly web application for real-time detection and performance evaluation metrics.

Uploaded by

Praveen Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Number Plate Detection of Vehicles

Aim:
To perform number plate detection of vehicles using python, computer vision,
OpenCV, stream lit.

Problem Statement:
The objective of this project is to develop an automated system for detecting vehicle
number plates using computer vision techniques. Manual identification of vehicle
plates is time-consuming, labor-intensive, and prone to human error. Automating this
process can significantly improve efficiency, accuracy, and reliability in various
applications such as law enforcement, parking management, and toll collection.

The primary goals of this system include:

 Detecting number plates from images of vehicles captured in different


environments and lighting conditions.
 Extracting number plate regions accurately while handling challenges like
occlusions, varying backgrounds, and different plate formats.
 Applying Optical Character Recognition (OCR) to extract the alphanumeric text
from the detected plates.
 Deploying the system as a user-friendly web application for real-time
processing.

Business Use Cases:


1. Traffic Management:
Automated vehicle identification can help track vehicles, enforce traffic
regulations, and issue fines for violations such as speeding and red-light
jumping.
2. Law Enforcement:
Helps police and security agencies track stolen or unauthorized vehicles,
aiding investigation
Enables seamless electronic toll collection without requiring vehicles to
stop, reducing congestion at toll plazas.
3. Parking Systems:
Automates access control in parking lots, allowing only authorized
vehicles and generating logs of entry and exit times.
4. Fleet Management:
Logistics and transportation companies can use automated number plate
recognition to monitor fleet movements and enhance tracking accuracy.
5. Security Monitoring:
Enhances security at gated communities, offices, and industrial sites by
ensuring only registered vehicles are allowed entry.
6. Urban Planning & Analytics:
Governments and municipalities can analyze traffic patterns to make
informed decisions on infrastructure development.

Approach:
The system follows a structured approach to ensure high detection accuracy and
efficiency:

1. Data Collection:
a. Acquiring images of vehicles from various environments, including
different angles, lighting conditions (day/night), and weather variations.
b. Using datasets with pre-annotated bounding boxes in YOLO format to
train the model.
2. Preprocessing:
a. Image resizing and normalization to ensure consistency.
b. Augmentation techniques like rotation, brightness adjustment, noise
addition, flipping, and cropping to improve model robustness.
c. Filtering out poor-quality images with excessive noise, blur, or low
resolution.
3. Model Training:
a. Using the YOLO (You Only Look Once) object detection framework for
efficient real-time number plate detection.
b. Fine-tuning hyperparameters such as learning rate, batch size, and
anchor box sizes.
c. Training the model using GPU acceleration to optimize performance.
4. Post Processing:
a. Extracting the detected number plate region and passing it through an
OCR system (Tesseract/EasyOCR) to convert the image into text.
b. Applying image binarization and contrast enhancement techniques to
improve OCR accuracy.
5. Deployment:
a. Integrating the trained model into a Streamlit-based web application.
b. Providing an interface where users can upload images or use real-time
webcam feeds for detection.
c. Displaying detected plates along with extracted text in a structured
format.

Streamlit Integration:

To ensure user-friendly access to the model, a Streamlit-based web application is


developed with the following features:

 Image Upload:
Users can upload images of vehicles for number plate detection.

 Webcam Support:
Real-time detection through live camera feed.

 Detection Results Display:


Bounding box visualization of detected number plates.

 OCR Output:
Extracted alphanumeric characters displayed alongside detected plates.

 Download & Export:


Users can download detection logs for future reference.

 Performance Dashboard:
Displays key metrics such as processing time, detection accuracy, and
confidence scores.

Exploratory Data Analysis (EDA):


Before training the model, thorough analysis is conducted on the dataset:
Dataset Composition:
Understanding dataset size, source, and balance of classes.

1. Bounding Box Distribution:


Checking the consistency and accuracy of annotations.

2. Image Quality Analysis:


Identifying common issues such as blurred or occluded plates.

3. Lighting Conditions & Weather Variability:


Analyzing dataset diversity to ensure robustness.

4. Class Frequency Distribution:


Evaluating variations in license plate styles across regions.

5. Augmentation Effects:
Assessing the impact of augmented samples on detection performance.

SOURCE CODE:

pip install opencv-python pytesseract numpy

from google.colab import files


from PIL import Image
import matplotlib.pyplot as plt

# Upload image
uploaded = files.upload()

# Get image path


image_path = list(uploaded.keys())[0]

# Open the image using PIL


image = Image.open(image_path)

# Display image using Matplotlib


plt.imshow(image)
plt.axis("off") # Hide axis for better visualization
plt.show()
OUTPUT:

CODE:
import cv2
import matplotlib.pyplot as plt

# Ensure the image path is correct and the file exists.


image_path = "car.jpg" # Replace with the correct path if needed
image = cv2.imread(image_path)

# Check if the image was loaded successfully.


if image is None:
print(f"Error: Could not load image at '{image_path}'")
else:
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Convert to
grayscale

cv2.imwrite("gray_car.jpg", gray_image) # Save the grayscale image

# Display the image using Matplotlib instead of cv2_imshow and waitKey


plt.imshow(gray_image, cmap='gray') # Use 'gray' colormap for
grayscale images
plt.axis('off') # Hide axis for better visualization
plt.show()

# Remove cv2.waitKey(0) and cv2.destroyAllWindows()


OUTPUT:

CODE:
import cv2
import matplotlib.pyplot as plt

# Load the pre-trained Haar Cascade for number plate detection


plate_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +
"haarcascade_russian_plate_number.xml")

# Load the image


image = cv2.imread("car.jpg") # Replace with your actual image path
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect number plates in the image


plates = plate_cascade.detectMultiScale(gray, scaleFactor=1.1,
minNeighbors=5, minSize=(30, 30))

# Draw bounding boxes around detected number plates


for (x, y, w, h) in plates:
cv2.rectangle(image, (x, y), (x + w, y + h), (255,0,0), 3) # Red
rectangle

# Convert image to RGB for display


image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

# Display the processed image


plt.figure(figsize=(10, 6))
plt.imshow(image_rgb)
plt.axis("off") # Hide axis
plt.show()

OUTPUT:

CODE:
import cv2
import numpy as np
from google.colab.patches import cv2_imshow # Import cv2_imshow for Colab

# Load image, ensuring the path is correct


image_path = 'car.jpg' # Update with the correct path if needed
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

# Check if image loaded successfully


if image is None:
print(f"Error: Could not load image at '{image_path}'. Please check
the path.")
else:
# Apply Canny edge detection
edges = cv2.Canny(image, 100, 200)

# Display results using cv2_imshow


cv2_imshow(edges) # Use cv2_imshow for displaying in Colab
OUTPUT:

RESULT:

Thus the number plate detection of vehicles using python are performed
successfully.
Brain Tumor Segmentation using Computer Vision

Aim:
To perform brain tumor segmentation using python, computer vision, OpenCV, stream
lit, segmentation

Problem statement:
Brain tumor segmentation is a critical task in medical imaging, playing a vital role in the
diagnosis, treatment planning, and monitoring of brain tumors. Accurate segmentation of tumor
regions from MRI scans is essential for determining the size, location, and shape of tumors, which
directly impacts the choice of treatment and surgical planning. However, the current process relies
heavily on manual segmentation by radiologists, which is not only time-consuming but also prone
to human error and inconsistencies. These limitations can lead to delays in diagnosis, misdiagnosis,
and suboptimal treatment outcomes. To address these challenges, this project aims to automate
brain tumor segmentation using computer vision techniques and OpenCV. By leveraging
advanced image processing algorithms, the system will process brain MRI images and their
corresponding mask images to accurately identify and segment tumor regions. The goal is to
develop a robust and efficient solution that can provide reliable and consistent segmentation
results, reducing the workload of medical professionals and improving diagnostic precision.

Automating this process will not only save time but also enhance the accuracy of tumor
detection, enabling faster and more informed decision-making for treatment planning. This is
particularly important in cases where timely intervention can significantly improve patient
outcomes. Additionally, the system can be integrated into telemedicine platforms, allowing remote
diagnosis and consultation, especially in areas with limited access to specialized medical
professionals. By automating brain tumor segmentation, this project aims to revolutionize the field
of medical imaging, making the process faster, more accurate, and accessible. It has the potential to
significantly improve patient care, reduce healthcare costs, and support medical research by
providing a reliable tool for analyzing tumor growth and treatment effectiveness

Business Use Cases:


1. Medical Diagnosis and Treatment Planning
 Use Case: Assist radiologists and oncologists in accurately diagnosing brain
tumors and planning treatments.
 Benefit: Improves diagnostic accuracy and enables personalized treatment
plans, leading to better patient outcomes.

2. Healthcare Automation

 Use Case: Automate repetitive tasks like tumor segmentation to reduce the
workload of medical professionals.
 Benefit: Saves time and allows healthcare providers to focus on critical tasks,
improving overall efficiency.

3. Telemedicine and Remote Diagnosis


 Use Case: Enable remote diagnosis and consultation by providing automated
segmentation results to doctors in underserved areas.
 Benefit: Expands access to specialized healthcare, especially in rural or
remote regions.

4. Research and Development

 Use Case: Provide researchers with precise tumor segmentation data for
studying tumor growth, treatment effectiveness, and drug development.
 Benefit: Accelerates medical research and innovation in oncology.

5. Surgical Planning

 Use Case: Provide surgeons with detailed tumor boundaries for pre-operative
planning.
 Benefit: Enhances surgical precision and reduces risks during brain tumor
removal procedures.

6. Radiation Therapy

 Use Case: Use segmented tumor regions to plan targeted radiation therapy.
 Benefit: Improves the accuracy of radiation delivery, minimizing damage to
healthy tissues.

7. Hospital Workflow Optimization

 Use Case: Integrate the system into hospital workflows to streamline the
diagnosis and treatment process.
 Benefit: Reduces waiting times and improves patient care efficiency.

8. Medical Training and Education

 Use Case: Use the system as a training tool for medical students and residents to
learn tumor segmentation.
 Benefit: Enhances the skills of future medical professionals through hands-on
practice.
9. Pharmaceutical Industry

 Use Case: Provide pharmaceutical companies with accurate tumor data for
clinical trials and drug testing.
 Benefit: Improves the reliability of clinical trial results and accelerates drug
development.

10. Insurance and Claims Processing

 Use Case: Use automated segmentation results to validate insurance claims


related to brain tumor treatments.
 Benefit: Reduces fraud and speeds up claim processing.

11. AI-Driven Healthcare Solutions

 Use Case: Integrate the system into AI-driven healthcare platforms for
comprehensive patient care.
 Benefit: Enhances the capabilities of AI systems in diagnosing and managing
brain tumors.

12. Global Health Initiatives

 Use Case: Deploy the system in low-resource settings to improve access to


brain tumor diagnosis and treatment.
 Benefit: Addresses global health disparities and improves outcomes for
patients in developing countries.

Approach:
1. Data Collection and Preparation

Step: Gather a dataset of brain MRI images and their corresponding mask images.
Action:
a. Ensure the dataset is diverse, covering various tumor types, sizes, and
locations.
b. Preprocess the images by normalizing intensity values and resizing them to
a standard resolution (e.g., 256x256 or 512x512).

2. Data Preprocessing

Step: Prepare the data for segmentation.


Action:
c. Convert MRI images to grayscale if necessary.
d. Apply noise reduction techniques (e.g., Gaussian blur) to improve image
quality.
e. Normalize pixel values to a fixed range (e.g., 0 to 1) for consistency.

3. Segmentation Algorithm Development

Step: Implement segmentation techniques using OpenCV.


Action:
f. Use thresholding to separate tumor regions from healthy tissue.
g. Apply edge detection (e.g., Canny edge detector) to identify tumor
boundaries.
h. Use contour detection to extract precise tumor regions from the mask
images.
i. Optionally, employ morphological operations (e.g., dilation, erosion) to
refine the segmentation results.

4. Model Training

Step: Train a machine learning or deep learning model for more accurate segmentation.
Action:
j. Use a U-Net, yolo or similar architecture for pixel-wise segmentation.
k. Train the model on the preprocessed MRI and mask images.
l. Validate the model using a separate test dataset.

5. Post-Processing

Step: Refine the segmentation results.


Action:
m. Remove small noise or false positives using morphological operations.
n. Smooth the tumor boundaries for better visualization.

6. Streamlit Integration

Step: Build a user-friendly web application for visualization and interaction.


Action:
o. Develop a Streamlit app to allow users to upload MRI images.
p. Display the original image, ground truth mask, and segmented tumor.
q. Provide options to download the segmentation results.

7. Evaluation and Testing


Step: Evaluate the performance of the segmentation system.
Action:
r. Use metrics like Dice coefficient, precision, recall, and IoU to
measure accuracy.
s. Test the system on unseen MRI images to ensure robustness.
t. Gather feedback from medical professionals for further improvements.

8. Deployment

Step: Deploy the system for real-world use in streamlit.

Streamlit Integration:
To ensure user-friendly access to the model, a Streamlit-based web application is
developed with the following features:

The project will include a Streamlit-based web application to make the system
accessible and user-friendly. The application will allow users to:

 Upload images for Segmentation of MRI.


 View the original input with detected objects highlighted.
 See segmented result
 Download the results for further analysis.

Exploratory Data Analysis (EDA):


Before training the model, thorough analysis is conducted on the dataset:

1. Image and Mask Visualization

 Step: Visualize a sample of images and their corresponding masks.


 Action:
o Display a few MRI images alongside their ground truth masks.
o Check if the masks accurately align with the tumor regions in the
images.
 Purpose: Understand the dataset structure and verify annotation quality.

2. Image Intensity Analysis

 Step: Analyze the intensity distribution of MRI images.


 Action:
o Plot histograms of pixel intensity values for both MRI images and masks.
o Identify intensity ranges for tumor and non-tumor regions.
 Purpose: Understand the contrast between tumor and healthy tissue.

3. Tumor Size and Shape Analysis

 Step: Examine the size and shape of tumors in the dataset.


 Action:
o Calculate the area and perimeter of tumor regions in the masks.
o Plot distributions of tumor sizes and shapes (e.g., circularity, aspect
ratio).
 Purpose: Identify variability in tumor characteristics and potential challenges
for segmentation.

4. Class Distribution Analysis

 Step: Analyze the distribution of tumor and non-tumor regions.


 Action:
o Calculate the ratio of tumor pixels to non-tumor pixels in the masks.
o Check for class imbalance that could affect model training.
 Purpose: Ensure the dataset is balanced or apply techniques to address
imbalance.

5. Dataset Splits Analysis

 Step: Evaluate the distribution of images across training, validation, and test
sets.
 Action:
o Check if the splits are representative of the overall dataset.
 Ensure no data leakage (e.g., similar images in both training and test
 Purpose: Ensure fair evaluation of the segmentation model.

6. Augmentation Impact Analysis

 Step: Assess the impact of data augmentation techniques.


 Action:
o Apply augmentations (e.g., rotation, flipping, scaling) to a sample image
and mask.
o sets).

 Purpose: Understand how augmentations affect the data and improve model
robustness.
SOURCE CODE:
!pip install opencv-python numpy matplotlib scikit-learn
tensorflow keras pillow streamlit

from google.colab import files


from PIL import Image
import matplotlib.pyplot as plt

# Upload image
uploaded = files.upload()

# Get image path


image_path = list(uploaded.keys())[0]

# Open the image using PIL


image = Image.open(image_path)

# Display image using Matplotlib


plt.imshow(image)
plt.axis("off") # Hide axis for better visualization
plt.show()

OUTPUT:

CODE:
import cv2
import matplotlib.pyplot as plt

# Ensure the image path is correct and the file exists.


image_path = "BrainTumor.jfif" # Replace with the correct path if needed
image = cv2.imread(image_path)

# Check if the image was loaded successfully.


if image is None:
print(f"Error: Could not load image at '{image_path}'")
else:
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Convert to
grayscale

cv2.imwrite("gray_BrainTumor.png", gray_image) # Save the grayscale


image

# Display the image using Matplotlib instead of cv2_imshow and waitKey


plt.imshow(gray_image, cmap='gray') # Use 'gray' colormap for
grayscale images
plt.axis('off') # Hide axis for better visualization
plt.show()

OUTPUT:

CODE:

import cv2
import matplotlib.pyplot as plt

# ... (previous code to load and display the grayscale image) ...

# Perform edge detection using Canny (or any other method)


edges = cv2.Canny(gray_image, 100, 200) # Adjust thresholds as needed

plt.figure(figsize=(10, 5))
plt.subplot(121), plt.imshow(image, cmap='gray'), plt.title('Original
Image')
plt.subplot(122), plt.imshow(edges, cmap='gray'), plt.title('Edge Image')
# Now 'edges' is defined
plt.show()

OUTPUT:

CODE:
import cv2
import numpy as np
import matplotlib.pyplot as plt

# Load image in grayscale


# Make sure the image path is correct and the file exists
image_path = 'BrainTumor.jfif' # Update with your image path
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

# Check if the image was loaded successfully


if image is None:
print(f"Error: Could not load image at '{image_path}'. Please check
the path and ensure the file exists.")
else:
# Apply Gaussian Blur to reduce noise
blurred = cv2.GaussianBlur(image, (5, 5), 0)

# Apply Adaptive Thresholding


adaptive_thresh = cv2.adaptiveThreshold(blurred, 255,
cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 2)

# Display results
plt.figure(figsize=(10, 5))
plt.subplot(121), plt.imshow(image, cmap='gray'), plt.title('Original
Image')
plt.subplot(122), plt.imshow(adaptive_thresh, cmap='gray'),
plt.title('Adaptive Threshold')
plt.show()
OUTPUT:

CODE:

import cv2
import numpy as np
import matplotlib.pyplot as plt

# Load image in grayscale


# Make sure the image path is correct and the file exists.
image_path = 'BrainTumor.jfif' # Update with your image path if
'BrainTumor.jpg' doesn't exist
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

# Check if the image was loaded successfully


if image is None:
print(f"Error: Could not load image at '{image_path}'. Please check
the path and ensure the file exists.")
else:
# Apply Gaussian Blur to reduce noise
blurred = cv2.GaussianBlur(image, (5, 5), 0)

# Apply Otsu’s Thresholding


_, otsu_thresh = cv2.threshold(blurred, 0, 255, cv2.THRESH_BINARY +
cv2.THRESH_OTSU)

# Display results
plt.figure(figsize=(10,5))
plt.subplot(121), plt.imshow(image, cmap='gray'), plt.title('Original
Image')
plt.subplot(122), plt.imshow(otsu_thresh, cmap='gray'),
plt.title('Otsu Threshold')
plt.show()
OUTPUT

RESULT:

Thus the brain tumor segmentation using python, computer vision, OpenCV,
stream lit, segmentation performed successfully.

You might also like