diff --git a/dev_New_project/LiveCarNumberPlateDetector.ipynb b/dev_New_project/LiveCarNumberPlateDetector.ipynb new file mode 100644 index 00000000..d18f080d --- /dev/null +++ b/dev_New_project/LiveCarNumberPlateDetector.ipynb @@ -0,0 +1,234 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "05NB1786\n", + "KA95NB1786\n", + "KA95N81786\n", + "KA05NB1786\n" + ] + } + ], + "source": [ + "import cv2\n", + "import numpy as np\n", + "from imutils.object_detection import non_max_suppression\n", + "\n", + "## ----------- Load Pre-trained Models ------------\n", + "model = cv2.dnn.readNet('frozen_east_text_detection.pb')\n", + "model1 = cv2.dnn.readNet('crnn.onnx')\n", + "\n", + "def most_likely(scores, char_set):\n", + " text = \"\"\n", + " for i in range(scores.shape[0]):\n", + " c = np.argmax(scores[i][0])\n", + " text += char_set[c]\n", + " return text\n", + "\n", + "def map_rule(text):\n", + " char_list = []\n", + " for i in range(len(text)):\n", + " if i == 0:\n", + " if text[i] != '-':\n", + " char_list.append(text[i])\n", + " else:\n", + " if text[i] != '-' and (not (text[i] == text[i - 1])):\n", + " char_list.append(text[i])\n", + " return ''.join(char_list)\n", + "\n", + "def best_path(scores, char_set):\n", + " text = most_likely(scores, char_set)\n", + " final_text = map_rule(text)\n", + " return final_text\n", + "\n", + "alphabet_set = \"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n", + "blank = '-'\n", + "\n", + "char_set = blank + alphabet_set\n", + "\n", + "def mainfn():\n", + " #img = cv2.imread(\"kia-seltos-car-number-plate-designs.jpeg\")\n", + " img = cv2.imread(\"pic.jpg\")\n", + " # use multiple of 32 to set the new img shape\n", + " height, width, _ = img.shape\n", + " new_height = (height//32)*32\n", + " new_width = (width//32)*32\n", + "\n", + " # get the ratio change in width and height\n", + " h_ratio = height/new_height\n", + " w_ratio = width/new_width\n", + "\n", + " blob = cv2.dnn.blobFromImage(img,1.0, (new_width, new_height), (123.68, 116.78, 103.94), True, False)\n", + "\n", + " model.setInput(blob)\n", + " (geometry, scores) = model.forward(model.getUnconnectedOutLayersNames())\n", + "\n", + " rectangles = []\n", + " confidence_score = []\n", + " for i in range(geometry.shape[2]):\n", + " for j in range(0, geometry.shape[3]):\n", + "\n", + " if scores[0][0][i][j] < 0.1:\n", + " continue\n", + "\n", + " bottom_x = int(j*4 + geometry[0][1][i][j])\n", + " bottom_y = int(i*4 + geometry[0][2][i][j])\n", + "\n", + "\n", + " top_x = int(j*4 - geometry[0][3][i][j])\n", + " top_y = int(i*4 - geometry[0][0][i][j])\n", + "\n", + " rectangles.append((top_x, top_y, bottom_x, bottom_y))\n", + " confidence_score.append(float(scores[0][0][i][j]))\n", + "\n", + " # use Non-max suppression to get the required rectangles\n", + " fin_boxes = non_max_suppression(np.array(rectangles), probs=confidence_score, overlapThresh=0.5)\n", + "\n", + " img_copy = img.copy()\n", + " chara = {}\n", + " for (x1, y1, x2, y2) in fin_boxes:\n", + "\n", + " x1 = int(x1 * w_ratio)\n", + " y1 = int(y1 * h_ratio)\n", + " x2 = int(x2 * w_ratio)\n", + " y2 = int(y2 * h_ratio)\n", + " \n", + " segment = img[y1:y2, x1:x2, :]\n", + " #segment = img[y1:y2, x1:x2, :]\n", + " segment_gray = cv2.cvtColor(segment, cv2.COLOR_BGR2GRAY)\n", + " \n", + " blob = cv2.dnn.blobFromImage(segment_gray, scalefactor=1/127.5, size=(100,32), mean=127.5)\n", + " model1.setInput(blob)\n", + " scores = model1.forward()\n", + " text = best_path(scores, char_set)\n", + " chara[x1] = text\n", + " #print(text)\n", + " \n", + " cv2.rectangle(img_copy, (x1, y1), (x2, y2), (0, 255, 0), 2)\n", + " cv2.putText(img_copy, text.strip(), (x1,y1-2), cv2.FONT_HERSHEY_COMPLEX, 0.5, (0,0,255),2)\n", + "\n", + " final=[]\n", + " for j in sorted(chara):\n", + " final.append(chara[j])\n", + " #print(final)\n", + " s = \"\"\n", + " s = s.join(final)\n", + " return s\n", + "\n", + "## ---------- Performing OCR in live video ----------\n", + "\n", + "cap = cv2.VideoCapture(0)\n", + "count=0\n", + "while cap.isOpened():\n", + " \n", + " count=count+1\n", + " ret, img = cap.read()\n", + " if count == 10:\n", + " cv2.imwrite(\"pic.jpg\", img)\n", + " #print(\"pic clicked\")\n", + " output_val = mainfn()\n", + " print(output_val) \n", + " #break\n", + " count=0\n", + " # use multiple of 32 to set the new img shape\n", + " height, width, _ = img.shape\n", + " new_height = (height//32)*32\n", + " new_width = (width//32)*32\n", + "\n", + " # get the ratio change in width and height\n", + " h_ratio = height/new_height\n", + " w_ratio = width/new_width\n", + "\n", + " blob = cv2.dnn.blobFromImage(img,1.0, (new_width, new_height), (123.68, 116.78, 103.94), True, False)\n", + "\n", + " model.setInput(blob)\n", + " (geometry, scores) = model.forward(model.getUnconnectedOutLayersNames())\n", + "\n", + " rectangles = []\n", + " confidence_score = []\n", + " for i in range(geometry.shape[2]):\n", + " for j in range(0, geometry.shape[3]):\n", + "\n", + " if scores[0][0][i][j] < 0.1:\n", + " continue\n", + "\n", + " bottom_x = int(j*4 + geometry[0][1][i][j])\n", + " bottom_y = int(i*4 + geometry[0][2][i][j])\n", + "\n", + "\n", + " top_x = int(j*4 - geometry[0][3][i][j])\n", + " top_y = int(i*4 - geometry[0][0][i][j])\n", + "\n", + " rectangles.append((top_x, top_y, bottom_x, bottom_y))\n", + " confidence_score.append(float(scores[0][0][i][j]))\n", + "\n", + " # use Non-max suppression to get the required rectangles\n", + " fin_boxes = non_max_suppression(np.array(rectangles), probs=confidence_score, overlapThresh=0.5)\n", + "\n", + " img_copy = img.copy()\n", + " for (x1, y1, x2, y2) in fin_boxes:\n", + "\n", + " x1 = int(x1 * w_ratio)\n", + " y1 = int(y1 * h_ratio)\n", + " x2 = int(x2 * w_ratio)\n", + " y2 = int(y2 * h_ratio)\n", + " \n", + " #segment = img[y1:y2+4, x1:x2+2, :]\n", + " segment = img[y1:y2, x1:x2, :]\n", + " segment_gray = cv2.cvtColor(segment, cv2.COLOR_BGR2GRAY)\n", + " \n", + " blob = cv2.dnn.blobFromImage(segment_gray, scalefactor=1/127.5, size=(100,32), mean=127.5)\n", + " model1.setInput(blob)\n", + " scores = model1.forward()\n", + " text = best_path(scores, char_set)\n", + " #print(text)\n", + "\n", + " cv2.rectangle(img_copy, (x1, y1), (x2, y2), (0, 255, 0), 2)\n", + " cv2.putText(img_copy, text.strip(), (x1,y1-2), cv2.FONT_HERSHEY_COMPLEX, 0.5, (0,0,255),2)\n", + "\n", + " cv2.imshow(\"Text Detection\", img_copy)\n", + " if cv2.waitKey(1) == 113:\n", + " break\n", + "\n", + "cap.release()\n", + "cv2.destroyAllWindows() \n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.3" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/dev_New_project/README.md b/dev_New_project/README.md new file mode 100644 index 00000000..76072abe --- /dev/null +++ b/dev_New_project/README.md @@ -0,0 +1 @@ +All about project diff --git a/dev_New_project/cgi-bin/api/main.py b/dev_New_project/cgi-bin/api/main.py new file mode 100644 index 00000000..8608c743 --- /dev/null +++ b/dev_New_project/cgi-bin/api/main.py @@ -0,0 +1,27 @@ +import requests +import json + +BASE = 'http://127.0.0.1:5000/' + +data = [{'Registration': 'MH01AV8866', + 'Owner': 'M//S PANDURONGA TIMBLO INDUSTRIES', + 'Maker': 'JAGUAR LAND ROVER INDIA LIMITED/ JAGUAR(XF 5.0LV8', + 'Vehicle': 'MOTOR CAR (L)', + 'Fuel_Type': 'PETROL', + 'Chassis': 'SAJAAC07P8BLRXXXXX', + 'Engine_Number': '10052323430XXXXX', + 'Registration_Date': '22-FEB-2011', + 'Insurance_Valid_Upto': '17-FEB-2012' +} + +] + +for i in range(len(data)): + response = requests.put(BASE + "vehicle/" + data[i]['Registration'], data[i]) + print(response.json()) + +input() + +response = requests.get(BASE + "vehicle/"+ data[0]['Registration']) + +print(json.dumps(response.json(), indent=1)) diff --git a/dev_New_project/cgi-bin/api/rto-api.py b/dev_New_project/cgi-bin/api/rto-api.py new file mode 100644 index 00000000..efa501ed --- /dev/null +++ b/dev_New_project/cgi-bin/api/rto-api.py @@ -0,0 +1,93 @@ +''' +Install all these packages with pip +Flask==1.1.2 +Flask-RESTful==0.3.8 +Flask-SQLAlchemy==2.4.3 +Jinja2==2.11.2 +SQLAlchemy==1.3.18 +''' + +from flask import Flask +from flask_restful import Api, Resource, reqparse, abort, fields, marshal_with +from flask_sqlalchemy import SQLAlchemy + + +app = Flask(__name__) +#Restful +api = Api(app) +# Creating/loading sqlite data base. Can be treated as fake database fo RTO +app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///rto.db' +db = SQLAlchemy(app) + +# Adding the columns to the model. +class RtoModel(db.Model): + Registration = db.Column(db.String(64), primary_key=True) + Owner = db.Column(db.String(64), nullable=False) + Maker = db.Column(db.String(64), nullable=False) + Vehicle = db.Column(db.String(64), nullable=False) + Fuel_Type = db.Column(db.String(64), nullable=False) + Chassis = db.Column(db.String(64), nullable=False) + Engine_Number = db.Column(db.String(64), nullable=False) + Registration_Date = db.Column(db.String(64), nullable=False) + Insurance_Valid_Upto = db.Column(db.String(64), nullable=False) + + def __repr__(self): + return f"RTO( Registration={Registration}, Owner={Owner}, Maker={Maker}, Vehicle={Vehicle}, Fuel_Type={Fuel_Type}, Chassis={Chassis}, Engine_Number={Engine_Number}, Registration_Date={Registration_Date}, Insurance_Valid_Upto={Insurance_Valid_Upto})" + + +# do the below thing only once for creating the table. +#db.create_all() + +video_put_args = reqparse.RequestParser() +video_put_args.add_argument('Registration', type=str, help='Registration number is required', required=True) +video_put_args.add_argument('Owner', type=str, help="Owner's Name is required", required=True) +video_put_args.add_argument('Maker', type=str, help='Maker details are required', required=True) +video_put_args.add_argument('Vehicle', type=str, help='Vehicle type is required', required=True) +video_put_args.add_argument('Fuel_Type', type=str, help='Type of Fuel is required', required=True) +video_put_args.add_argument('Chassis', type=str, help='Chassis Number is required', required=True) +video_put_args.add_argument('Engine_Number', type=str, help='Engine Number is required', required=True) +video_put_args.add_argument('Registration_Date', type=str, help='Registration Date is required', required=True) +video_put_args.add_argument('Insurance_Valid_Upto', type=str, help='Insurance Due Date is required', required=True) + + +Resource_fields = { + 'Registration' : fields.String, + 'Owner': fields.String, + 'Maker': fields.String, + 'Vehicle': fields.String, + 'Fuel_Type': fields.String, + 'Chassis': fields.String, + 'Engine_Number': fields.String, + 'Registration_Date': fields.String, + 'Insurance_Valid_Upto': fields.String +} + + +class RTO(Resource): + @marshal_with(Resource_fields) + def get(self, vehicle_number): + result = RtoModel.query.filter_by(Registration=vehicle_number).first() + if not result: + abort(404, message="Vahicle details Not found...") + return result + + @marshal_with(Resource_fields) + def put(self, vehicle_number): + args = video_put_args.parse_args() + result = RtoModel.query.filter_by(Registration=vehicle_number).first() + if result: + abort(409, message="Vehicle already exists...") + vehicle = RtoModel(Registration=vehicle_number, Owner=args['Owner'], Maker=args['Maker'], Vehicle=args['Vehicle'], Fuel_Type=args['Fuel_Type'], Chassis=args['Chassis'], Engine_Number=args['Engine_Number'], Registration_Date=args['Registration_Date'], Insurance_Valid_Upto=args['Insurance_Valid_Upto']) + db.session.add(vehicle) + db.session.commit() + return vehicle , 201 + + def delete(self, video_id): + return "", 204 + +api.add_resource(RTO, "/vehicle/") + + + +if __name__ == '__main__': + app.run(debug=True) \ No newline at end of file diff --git a/dev_New_project/cgi-bin/api/rto.db b/dev_New_project/cgi-bin/api/rto.db new file mode 100644 index 00000000..0eb73455 Binary files /dev/null and b/dev_New_project/cgi-bin/api/rto.db differ diff --git a/dev_New_project/cgi-bin/get-info.py b/dev_New_project/cgi-bin/get-info.py new file mode 100644 index 00000000..d0affab0 --- /dev/null +++ b/dev_New_project/cgi-bin/get-info.py @@ -0,0 +1,19 @@ +#!/usr/bin/python3 + +print("content-type: text/html") +print() + +import cgi +import requests +import json + +BASE = 'http://127.0.0.1:5000/' + +field = cgi.FieldStorage() +vehicle_number = field.getvalue("vehicle_number") + + +response = requests.get(BASE + "vehicle/" + vehicle_number) +responseJson = json.dumps(response.json(), indent=1) + +print(responseJson.replace("{", "").replace("}", "")) \ No newline at end of file diff --git a/dev_New_project/crnn.onnx b/dev_New_project/crnn.onnx new file mode 100644 index 00000000..6eee38c7 Binary files /dev/null and b/dev_New_project/crnn.onnx differ diff --git a/dev_New_project/frozen_east_text_detection.pb b/dev_New_project/frozen_east_text_detection.pb new file mode 100644 index 00000000..5702180c Binary files /dev/null and b/dev_New_project/frozen_east_text_detection.pb differ diff --git a/dev_New_project/html/button.js b/dev_New_project/html/button.js new file mode 100644 index 00000000..d500a98e --- /dev/null +++ b/dev_New_project/html/button.js @@ -0,0 +1,24 @@ + +function getInfo(vehicle_number) { + + var xhr = new XMLHttpRequest(); + xhr.open("GET", "http://192.168.153.207/cgi-bin/get-info.py?vehicle_number=" + vehicle_number, true); + + xhr.send(); + + // Output from above url + + xhr.onload = function () { + var output = xhr.responseText; + document.getElementById("output").innerHTML = output; + } + +} + +function printer(id) { + var keyword = document.getElementById(id); + return keyword.value; +} + + + diff --git a/dev_New_project/html/index.html b/dev_New_project/html/index.html new file mode 100644 index 00000000..7f84ae58 --- /dev/null +++ b/dev_New_project/html/index.html @@ -0,0 +1,57 @@ + + + RTO Connect + + + + +
+ + +
+
+
+
Press this button to open your webcam. + It will capture your car image and give you number plate details. + +
+ +
+ + +
+
+ + +
+
CAR INFORMATION
+
+                
+ +
+
+
+
+ + + +
+ +
+
+
+
+ +
+
+ + +
+
+ + + + + \ No newline at end of file diff --git a/dev_New_project/html/static/css/images/car.png b/dev_New_project/html/static/css/images/car.png new file mode 100644 index 00000000..0b96327c Binary files /dev/null and b/dev_New_project/html/static/css/images/car.png differ diff --git a/dev_New_project/html/static/css/images/city.png b/dev_New_project/html/static/css/images/city.png new file mode 100644 index 00000000..e6540419 Binary files /dev/null and b/dev_New_project/html/static/css/images/city.png differ diff --git a/dev_New_project/html/static/css/images/road.jpg b/dev_New_project/html/static/css/images/road.jpg new file mode 100644 index 00000000..3cc2e660 Binary files /dev/null and b/dev_New_project/html/static/css/images/road.jpg differ diff --git a/dev_New_project/html/static/css/images/sky.jpeg b/dev_New_project/html/static/css/images/sky.jpeg new file mode 100644 index 00000000..c7f3e91e Binary files /dev/null and b/dev_New_project/html/static/css/images/sky.jpeg differ diff --git a/dev_New_project/html/static/css/images/wheel.png b/dev_New_project/html/static/css/images/wheel.png new file mode 100644 index 00000000..456f9106 Binary files /dev/null and b/dev_New_project/html/static/css/images/wheel.png differ diff --git a/dev_New_project/html/static/css/style.css b/dev_New_project/html/static/css/style.css new file mode 100644 index 00000000..f9e022be --- /dev/null +++ b/dev_New_project/html/static/css/style.css @@ -0,0 +1,215 @@ +* +{ + margin: 0; + padding: 0; +} +body{ + background-image: url(./images/sky.jpeg); +} + +.hero +{ + height: 60%; + width: 100%; + /* background-image: url(./images/sky.jpeg); */ + background-size: cover; + background-position: center; + position: relative; + overflow-x: hidden; +} +.highway +{ + height: 200px; + width: 500%; + display: block; + background-image: url("./images/road.jpg"); + position: absolute; + bottom:0; + left:0; + right:0; + z-index:1; + animation: highway 5s linear infinite; +} +@keyframes highway +{ + 100%{ + transform: translateX(-3400px); + } +} +.city +{ + height: 250px; + width: 500%; + background-image: url("./images/city.png"); + position: absolute; + bottom: 200px; + left:0; + right:0; + display:block; + z-index: 1; + background-repeat: repeat-x; + animation: city 20s linear infinite; +} +@keyframes city +{ + 100%{ + transform: translateX(-1400px); + } +} +.car +{ + width: 400px; + left: 50%; + bottom: 100px; + transform: translateX(-50%); + position: absolute; + z-index: 2; +} +.car img +{ + width: 100%; + animation:car 1s linear infinite; +} +@keyframes car +{ + 100%{ + transform: translateY(-1px); + } + 50%{ + transform: translateY(1px); + } + 0%{ + transform: translateY(-1px); + } +} +.wheel +{ + left: 50%; + bottom: 178px; + transform: translateX(-50%); + position: absolute; + z-index: 2; +} +.wheel img +{ + width: 72px; + height: 72px; + animation: wheel 1s linear infinite; +} +.back-wheel +{ + left: -165px; + position: absolute; +} +.front-wheel +{ + left: 80px; + position: absolute; +} +@keyframes wheel +{ + 100%{ + transform: rotate(360deg); + } +} + +.top{ + height: 50%; + width: 100%; + /* background-image: url("./images/sky.jpeg"); */ + background-size: cover; +} + +.nav-bar{ +border-radius: 20px; +margin-left: 10px; +margin-right: 10px; +border: solid black 2px; +height: 20%; +text-align: center; +padding-top: 25px; +margin-top: 5px; +background-color: black; +color:white +} + +#btn{ + height: 60%; + border-radius: 10px; + border: solid black 3px; + margin: 10px; + margin-left: 25px; + margin-bottom: 0px; + background-color: rgb(176, 211, 245); +} + +.submit-btn{ + border: solid black; + height: 40px; + width: 100px; + margin-top: 40px; + margin-left: 20%; + border-radius: 20px; + text-decoration: black; + background-color: red; + color: white; + font-size: 20px; +} +#btn-info{ + padding-left: 10px; + margin-top: 20px; + font-size: 25px; + height: 60px; + font-family:Arial, Helvetica, sans-serif +} + +.class1{ + width: 48%; + float: left; +} + + +#d2{ + background-color: rgb(176, 211, 245); + height: 60%; + border-radius: 10px; + border: solid black 3px; + margin: 10px; + margin-left: 25px; + margin-bottom: 0px; + +} + +#car-top{ + background-color: rgb(175, 18, 18); + border: bottom solid black 3px; + border-radius: 10px; + text-align: center; + font-size: large; + color: cornsilk; + height: 30px; +} +#output{ + text-align: left; + font-size: medium; + padding-left: 10px; +} + +#lname{ + margin: 50px; + height: 40px; + width: 250px; + border-radius: 15px; + text-align: center; + font-size: large; +} + +::placeholder{ + text-align: center; +} + +#forma{ + font-size: 25px; + margin-left: 10px; +} +