Commit 01e4a4bf authored by Diyamantha N.K.A.G.O's avatar Diyamantha N.K.A.G.O

Merge branch 'IT18223118' into 'master'

It18223118

See merge request !2
parents d6ead86e 14149bf7
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
from PIL import ImageFont
import re
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
# Paddleocr supports Chinese, English, French, German, Korean, and Japanese.
# You can set the parameter `lang` as `ch`, `en`, `fr`, `german`, `korean`, `japan`
# to switch the language model in order.
ocr = PaddleOCR(use_angle_cls=True, lang='en') # need to run only once to download and load the model into memory
provineces = ['NP' , 'SP' , 'EP' , 'WP', 'SG' , 'NC' , 'NW' , 'CP' , 'UP' ]
numbers_range = '0123456789'
letters_range = 'W,E,S,C,N,P,U'
def1 = 'PF'
def2 = '2969'
def get_licsence_number( model , image_path):
result = model.ocr(image_path, cls=True)
result = ocr.ocr(image_path, cls=True)
res = result[0][0][1][0]
return res
def pattern(default , number):
if number is not None :
letters = number.split('-')[0].strip()
if len(letters) > 2 and letters.isupper():
province = letters[:len(letters) - 2]
matches = [item for item in provineces if item.startswith(province)]
if len(matches) > 0:
p = matches[0]
result = p + number[len(letters) - 2:]
return result
else:
return None
This diff is collapsed.
File added
import cv2
import os
video_cap = cv2.VideoCapture('sample100.mp4')
if not video_cap.isOpened():
print("done")
exit()
if not os.path.exists("frames"):
os.mkdir("frames")
count = 0
while True :
ret , frame = video_cap.read()
if not ret:
break
frame_filename = f'frames/frame{count:04d}.jpg'
cv2.imwrite(frame_filename , frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
count+=1
print(count)
video_cap.release()
cv2.destroyAllWindows()
import smtplib
def sending(number, email , password , to) :
gmail_user = email
gmail_password = password
sent_from = gmail_user
subject = 'Detected as Lane violation'
email_text = f"Vehicle number : {number}"
try:
smtp_server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
smtp_server.ehlo()
smtp_server.login(gmail_user, gmail_password)
smtp_server.sendmail(sent_from, to, email_text)
smtp_server.close()
print ("Email sent successfully!")
except Exception as ex:
print ("Something went wrong….",ex)
\ No newline at end of file
// document.getElementById("reportLaneViolation").addEventListener("click", function () {
// alert("Lane violation reported!");
// });
// document.getElementById("reportHighSpeedViolation").addEventListener("click", function () {
// alert("High-speed violation reported!");
// });
// document.getElementById("reportRedLightViolation").addEventListener("click", function () {
// alert("Red light violation reported!");
// });
// document.getElementById("reportFiningSystem").addEventListener("click", function () {
// alert("Fining System reported!");
// });
document.getElementById("reportLaneViolation").addEventListener("click", function () {
// Send a POST request to /start_detection when the button is clicked
fetch('/start_detection', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(function (response) {
return response.json();
})
.then(function (data) {
// Display the response message in an alert
alert(data.message);
})
.catch(function (error) {
console.error('Error:', error);
});
});
document.getElementById("reportHighSpeedViolation").addEventListener("click", function () {
// Send a POST request to /detect_high_speed when the button is clicked
fetch('/start_detection_speed', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(function (response) {
return response.json();
})
.then(function (data) {
// Display the response message
alert(data.message);
})
.catch(function (error) {
console.error('Error:', error);
});
});
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #333;
color: #fff;
text-align: center;
padding: 1rem;
}
main {
padding: 2rem;
}
section {
border: 1px solid #ccc;
padding: 1rem;
margin-bottom: 1rem;
}
button {
background-color: #333;
color: #fff;
border: none;
padding: 0.5rem 1rem;
cursor: pointer;
}
footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 0.5rem;
}
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
<style>
/* Add CSS for the grid layout */
main {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(2, auto);
gap: 20px;
}
</style>
<title>Motor Traffic Department</title>
</head>
<body>
<header>
<h1>Motor Traffic Department</h1>
</header>
<main>
<section id="laneViolation">
<h2>Lane Violation</h2>
<button id="reportLaneViolation"><img src="{{ url_for('static', filename='images/lane_violation.png') }}" alt="Report Lane Violation"></button>
</section>
<section id="highSpeedViolation">
<h2>High Speed Violation</h2>
<button id="reportHighSpeedViolation"><img src="{{ url_for('static', filename='images/high_speed.png') }}" alt="Report High Speed Violation"></button>
</section>
<section id="redLightViolation">
<h2>Red Light Violation</h2>
<button id="reportRedLightViolation"><img src="{{ url_for('static', filename='images/traffic_light.jpg') }}" alt="Report Red Light Violation"></button>
</section>
<section id="finingSystem">
<h2>Fining System</h2>
<button id="reportFiningSystem"><img src="{{ url_for('static', filename='images/fining.png') }}" alt="Open Fining System"></button>
</section>
</main>
<footer>
<p>&copy; 2023 Motor Traffic Department</p>
</footer>
<script src="{{ url_for('static', filename='scripts.js') }}"></script>
</body>
</html>
from paddleocr import PaddleOCR,draw_ocr
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
# Paddleocr supports Chinese, English, French, German, Korean and Japanese.
# You can set the parameter `lang` as `ch`, `en`, `fr`, `german`, `korean`, `japan`
# to switch the language model in order.
ocr = PaddleOCR(use_angle_cls=True, lang='en') # need to run only once to download and load model into memory
img_path = 'temporary_cropped.jpg'
result = ocr.ocr(img_path, cls=True)
print(result[0][0][1][0])
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment