Commit d47bd4d0 authored by Alahakoon K.M.R.A.B's avatar Alahakoon K.M.R.A.B

Merge branch 'master' into 'it19170008'

Master

See merge request !17
parents 50f6be2d 7bbb8736
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="45">
<item index="0" class="java.lang.String" itemvalue="opencv-python" />
<item index="1" class="java.lang.String" itemvalue="cmake" />
<item index="2" class="java.lang.String" itemvalue="numpy" />
<item index="3" class="java.lang.String" itemvalue="dlib" />
<item index="4" class="java.lang.String" itemvalue="thop" />
<item index="5" class="java.lang.String" itemvalue="scikit-image" />
<item index="6" class="java.lang.String" itemvalue="opencv-contrib-python" />
<item index="7" class="java.lang.String" itemvalue="wincertstore" />
<item index="8" class="java.lang.String" itemvalue="networkx" />
<item index="9" class="java.lang.String" itemvalue="tifffile" />
<item index="10" class="java.lang.String" itemvalue="Flask-Cors" />
<item index="11" class="java.lang.String" itemvalue="PyYAML" />
<item index="12" class="java.lang.String" itemvalue="torch" />
<item index="13" class="java.lang.String" itemvalue="torchvision" />
<item index="14" class="java.lang.String" itemvalue="mysql-connector-python" />
<item index="15" class="java.lang.String" itemvalue="pandas" />
<item index="16" class="java.lang.String" itemvalue="tqdm" />
<item index="17" class="java.lang.String" itemvalue="regex" />
<item index="18" class="java.lang.String" itemvalue="mediapipe" />
<item index="19" class="java.lang.String" itemvalue="seaborn" />
<item index="20" class="java.lang.String" itemvalue="better-profanity" />
<item index="21" class="java.lang.String" itemvalue="colorama" />
<item index="22" class="java.lang.String" itemvalue="PyWavelets" />
<item index="23" class="java.lang.String" itemvalue="imutils" />
<item index="24" class="java.lang.String" itemvalue="pytz" />
<item index="25" class="java.lang.String" itemvalue="torchaudio" />
<item index="26" class="java.lang.String" itemvalue="Flask" />
<item index="27" class="java.lang.String" itemvalue="Pillow" />
<item index="28" class="java.lang.String" itemvalue="flashtext" />
<item index="29" class="java.lang.String" itemvalue="unidecode" />
<item index="30" class="java.lang.String" itemvalue="sklearn" />
<item index="31" class="java.lang.String" itemvalue="nltk" />
<item index="32" class="java.lang.String" itemvalue="beautifulsoup4" />
<item index="33" class="java.lang.String" itemvalue="chardet" />
<item index="34" class="java.lang.String" itemvalue="pdfminer.six" />
<item index="35" class="java.lang.String" itemvalue="six" />
<item index="36" class="java.lang.String" itemvalue="certifi" />
<item index="37" class="java.lang.String" itemvalue="MarkupSafe" />
<item index="38" class="java.lang.String" itemvalue="scipy" />
<item index="39" class="java.lang.String" itemvalue="chumpy" />
<item index="40" class="java.lang.String" itemvalue="matplotlib" />
<item index="41" class="java.lang.String" itemvalue="opendr" />
<item index="42" class="java.lang.String" itemvalue="protobuf" />
<item index="43" class="java.lang.String" itemvalue="grpcio" />
<item index="44" class="java.lang.String" itemvalue="click" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="..\:/Users/dilsh/AndroidStudioProjects/VehicleParkingSystem/app/src/main/res/layout/activity_dashboard.xml" value="0.22826086956521738" />
<entry key="..\:/Users/dilsh/AndroidStudioProjects/VehicleParkingSystem/app/src/main/res/layout/activity_login.xml" value="0.22826086956521738" />
<entry key="..\:/Users/dilsh/AndroidStudioProjects/VehicleParkingSystem/app/src/main/res/layout/activity_main.xml" value="0.22826086956521738" />
<entry key="..\:/Users/dilsh/AndroidStudioProjects/VehicleParkingSystem/app/src/main/res/layout/activity_parking_slots.xml" value="0.22826086956521738" />
<entry key="..\:/Users/dilsh/AndroidStudioProjects/VehicleParkingSystem/app/src/main/res/layout/activity_register.xml" value="0.2" />
<entry key="..\:/Users/dilsh/AndroidStudioProjects/VehicleParkingSystem/app/src/main/res/layout/custom_entrance_details.xml" value="0.22826086956521738" />
<entry key="..\:/Users/dilsh/AndroidStudioProjects/VehicleParkingSystem/app/src/main/res/layout/custom_parking_violation.xml" value="0.22826086956521738" />
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (tf_obj_detect)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
......@@ -78,4 +78,6 @@ Vehicle Parking System(2022-235)
Objective:-
Ensure the safety of the vehicle while parked in the vehicle-park using image processing and Machine Learning.
Also display of unsecured status by notification.
\ No newline at end of file
Also display of unsecured status by notification.
test
\ No newline at end of file
from flask import Flask, request
from flask_cors import CORS
import json
import cv2
import base64
import component_1.slot_detector as slot_detector
import component_1.waiting_time_pred as waiting_time_pred
import component_2.parking_violation as parking_violation_obj
import component_3.video_tester as number_plate_detector
import component_3.parking_traffic_pred as parking_traffic_pred
import component_4.human_action_detector as human_action_detector
app = Flask(__name__)
CORS(app)
@app.route('/slot_availability', methods=['GET', 'POST'])
def slot_availability():
slot_list = slot_detector.get_number_of_space()
return_str = '{ '
for i in range(0, 12):
return_str += '"' + str(i) + '" : ' + str(slot_list[i]) + ','
return_str += ' "average_waiting_time" : ' + str(waiting_time_pred.get_waiting_time()) + '}'
print(return_str)
return json.loads(return_str)
@app.route('/parking_violation', methods=['GET', 'POST'])
def parking_violation():
if parking_violation_obj.is_vehicle_parked_correctly():
return_str = ' { "status" : 1 }'
else:
return_str = ' { "status" : 0 }'
return json.loads(return_str)
@app.route('/enternce', methods=['GET', 'POST'])
def enternce():
number_plate = number_plate_detector.get_number_plate()
return_str = '{ "number_plate" : "' + str(number_plate) + '", "type" : "car" }'
return json.loads(return_str)
@app.route('/traffic', methods=['GET', 'POST'])
def traffic():
traffic_data = parking_traffic_pred.get_traffic_next_week()
return_str = '{ "parking_traffic_next_week" : ['
for i in range(len(traffic_data)):
if i == len(traffic_data) - 1:
return_str += str(traffic_data[i])
else:
return_str += str(traffic_data[i]) + ', '
return_str += ']}'
return json.loads(return_str)
@app.route('/threat', methods=['GET', 'POST'])
def threat():
if human_action_detector.get_human_thred_temp():
return_str = '{ "status" : 1 }'
else:
return_str = '{ "status" : 0 }'
return json.loads(return_str)
@app.route('/image', methods=['GET', 'POST'])
def image():
return_str = '{ "base64_image" : "' + str(get_base_64()) + '" }'
return json.loads(return_str)
def get_base_64():
img = cv2.imread('test.jpg')
retval, buffer = cv2.imencode('.jpg', img)
jpg_as_text = base64.b64encode(buffer)
return jpg_as_text
if __name__ == '__main__':
app.run(host="0.0.0.0", port=3000, debug=True)
package com.example.vehicleparkingsystem;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.vehicleparkingsystem.Models.Users;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class Register extends AppCompatActivity {
EditText editText1;
EditText editText2;
EditText editText3;
EditText editText4;
EditText editText5;
EditText editText6;
Button reg;
TextView textView;
FirebaseDatabase rootNode;
DatabaseReference reference;
FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
editText1=(EditText)findViewById(R.id.Uname);
editText2=(EditText)findViewById(R.id.Remail);
editText3=(EditText)findViewById(R.id.Age);
editText4=(EditText)findViewById(R.id.contct);
editText5=(EditText)findViewById(R.id.password);
editText6=(EditText)findViewById(R.id.vehicle);
reg=(Button)findViewById(R.id.register);
textView=(TextView)findViewById(R.id.gotologin);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Register.this, MainActivity.class);
startActivity(intent);
}
});
firebaseAuth=FirebaseAuth.getInstance();
reg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
reference = FirebaseDatabase.getInstance().getReference("User");
// reference = rootNode.getReference("Users");
final String namee = editText1.getText().toString();
final String emaill = editText2.getText().toString();
final String age = editText3.getText().toString();
final String phonee = editText4.getText().toString();
final String pass = editText5.getText().toString();
final String vehicle = editText6.getText().toString();
if (!validateUserName() | !validateEmail() | !validateAge() | !validatePhone() | !validatePassword()) {
Toast.makeText(Register.this, "Sign up failed", Toast.LENGTH_SHORT).show();
}
else{
firebaseAuth.createUserWithEmailAndPassword(emaill, pass)
.addOnCompleteListener(Register.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
String userid = user.getUid();
Users members = new Users(namee,emaill,age,phonee,vehicle,pass);
reference.child(userid).setValue(members);
System.out.println(members);
Toast.makeText(Register.this, "Sign up successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(Register.this, Dashboard.class);
startActivity(intent);
} else {
Toast.makeText(Register.this, "Sign up failed", Toast.LENGTH_SHORT).show();
}
}
});
}
}
});
}
public boolean validateUserName() {
String value = editText1.getText().toString();
String noWhiteSpace = "\\A\\w{4,20}\\z";
if (value.isEmpty()) {
editText1.setError("Field cannot be empty");
return false;
} else if (value.length() >= 15) {
editText1.setError("Username too long. limit to 15 characters");
return false;
} else if (!value.matches(noWhiteSpace)) {
editText1.setError("White Spaces are not allowed");
return false;
} else {
editText1.setError(null);
return true;
}
}
public boolean validateEmail() {
String value = editText2.getText().toString();
String emailPattern = "[a-zA-Z0-9._-]+@[a-z].+[a-z]+\\.+[a-z]+"; //Regex Expression
if (value.isEmpty()) {
editText2.setError("Field cannot be empty");
return false;
} else if (!value.matches(emailPattern)) {
editText2.setError("Invalid email address");
return false;
} else {
editText2.setError(null);
return true;
}
}
public boolean validateAge() {
String value = editText3.getText().toString();
if (value.isEmpty()) {
editText3.setError("Field cannot be empty");
return false;
} else {
editText3.setError(null);
return true;
}
}
public boolean validatePhone() {
String value = editText4.getText().toString();
if (value.isEmpty()) {
editText4.setError("Field cannot be empty");
return false;
} else {
editText4.setError(null);
return true;
}
}
public boolean validatePassword() {
String value = editText5.getText().toString();
String password = "^" +
//"(?=.*[0-9])" + //at least 1 digit
//"(?=.*[a-z])" + //at least 1 lower case letter
//"(?=.*[A-Z])" + //at least 1 upper case letter
"(?=.*[a-zA-Z])" + //any letter
"(?=.*[@#$%^&+=])" + //at least 1 special character
"(?=\\S+$)" + //no white spaces
".{2,}" + //at least 2 characters
"$";
if (value.isEmpty()) {
editText5.setError("Field cannot be empty");
return false;
} else if (!value.matches(password)) {
editText5.setError("Password must have at least 1 special character, 2 numbers and letters");
return false;
} else {
editText5.setError(null);
return true;
}
}
}
\ No newline at end of file
import torch
import json
import cv2
import math
import os
import random
model_vehicle = torch.hub.load('ultralytics/yolov5', 'yolov5s')
guide_line_database = [527, 215, 611, 345] # sample guideline
def is_inside(x1, y1, x1b, y1b, x2, y2, x2b, y2b):
if x1 >= x2 and y1 >= y2 and x1b <= x2b and y1b <= y2b:
return True
else:
return False
def is_vehicle_parked_correctly(slot_index=0):
sample_imgs = os.listdir('component_2/sample_data')
img = cv2.imread('component_2/sample_data/' + str(random.choice(sample_imgs)))
result = model_vehicle(img)
json_string = result.pandas().xyxy[0].to_json(orient='records')
json_obj = json.loads(json_string)
object_list = []
for i in json_obj:
x = int(i["xmin"])
y = int(i["ymin"])
w = int(i["xmax"])
h = int(i["ymax"])
object_list.append([x, y, w, h])
if len(json_obj) == 0:
return True
return is_inside(object_list[slot_index][0], object_list[slot_index][1], object_list[slot_index][2],
object_list[slot_index][3], guide_line_database[0], guide_line_database[1], guide_line_database[2],
guide_line_database[3])
# print(is_vehicle_parked_correctly())
This diff is collapsed.
import pandas as pd
import numpy as np
from statsmodels.tsa.stattools import adfuller
from pmdarima import auto_arima
from statsmodels.tsa.arima.model import ARIMA
from sklearn.metrics import mean_squared_error
from math import sqrt
import warnings
warnings.filterwarnings("ignore")
df = pd.read_csv('data.csv', index_col='Date', parse_dates=True)
df = df.dropna()
print('Shape of data', df.shape)
print(df.head())
def adf_test(dataset):
dftest = adfuller(dataset, autolag='AIC')
print("1. ADF : ", dftest[0])
print("2. P-Value : ", dftest[1])
print("3. Num Of Lags : ", dftest[2])
print("4. Num Of Observations Used For ADF Regression and Critical Values Calculation :", dftest[3])
print("5. Critical Values :")
for key, val in dftest[4].items():
print("\t", key, ": ", val)
adf_test(df['no_of_vehicles'])
stepwise_fit = auto_arima(df['no_of_vehicles'], suppress_warnings=True)
print(stepwise_fit.summary())
print(df.shape)
train = df.iloc[:-30]
test = df.iloc[-30:]
print(train.shape, test.shape)
print(test.iloc[0], test.iloc[-1])
model = ARIMA(train['no_of_vehicles'], order=(1, 0, 0))
model = model.fit()
model.summary()
start = len(train)
end = len(train) + len(test) - 1
pred = model.predict(start=start, end=end, typ='levels').rename('ARIMA predictions')
# pred.index=index_future_dates
pred.plot(legend=True)
test['no_of_vehicles'].plot(legend=True)
rmse = sqrt(mean_squared_error(pred, test['no_of_vehicles']))
print(rmse)
model2 = ARIMA(df['no_of_vehicles'], order=(1, 0, 0))
model2 = model2.fit()
df.tail()
model2.save('no_of_vehicles.pkl')
Date,no_of_vehicles
2020.06.01,620
2020.06.02,586
2020.06.03,1061
2020.06.04,434
2020.06.05,597
2020.06.06,683
2020.06.07,447
2020.06.08,408
2020.06.09,788
2020.06.10,1019
2020.06.11,149
2020.06.12,813
2020.06.13,448
2020.06.14,119
2020.06.15,74
2020.06.16,565
2020.06.17,64
2020.06.18,928
2020.06.19,985
2020.06.20,271
2020.06.21,998
2020.06.22,294
2020.06.23,930
2020.06.24,71
2020.06.25,650
2020.06.26,440
2020.06.27,103
2020.06.28,196
2020.06.29,890
2020.06.30,170
2020.07.01,637
2020.07.02,134
2020.07.03,995
2020.07.04,104
2020.07.05,757
2020.07.06,334
2020.07.07,724
2020.07.08,1076
2020.07.09,16
2020.07.10,1076
2020.07.11,516
2020.07.12,792
2020.07.13,617
2020.07.14,221
2020.07.15,624
2020.07.16,457
2020.07.17,762
2020.07.18,736
2020.07.19,374
2020.07.20,404
2020.07.21,671
2020.07.22,867
2020.07.23,394
2020.07.24,716
2020.07.25,11
2020.07.26,904
2020.07.27,76
2020.07.28,755
2020.07.29,98
2020.07.30,481
2020.07.31,696
2020.08.01,446
2020.08.02,947
2020.08.03,1126
2020.08.04,1149
2020.08.05,939
2020.08.06,582
2020.08.07,841
2020.08.08,1011
2020.08.09,156
2020.08.10,1070
2020.08.11,167
2020.08.12,904
2020.08.13,165
2020.08.14,769
2020.08.15,609
2020.08.16,216
2020.08.17,948
2020.08.18,568
2020.08.19,1012
2020.08.20,826
2020.08.21,741
2020.08.22,694
2020.08.23,766
2020.08.24,961
2020.08.25,680
2020.08.26,21
2020.08.27,489
2020.08.28,21
2020.08.29,1061
2020.08.30,341
2020.08.31,1071
2020.09.01,510
2020.09.02,983
2020.09.03,1168
2020.09.04,65
2020.09.05,515
2020.09.06,233
2020.09.07,186
2020.09.08,1052
2020.09.09,366
2020.09.10,423
2020.09.11,55
2020.09.12,536
2020.09.13,589
2020.09.14,412
2020.09.15,545
2020.09.16,177
2020.09.17,968
2020.09.18,1063
2020.09.19,1156
2020.09.20,435
2020.09.21,703
2020.09.22,1104
2020.09.23,209
2020.09.24,454
2020.09.25,598
2020.09.26,615
2020.09.27,1155
2020.09.28,237
2020.09.29,261
2020.09.30,859
2020.10.01,1156
2020.10.02,1091
2020.10.03,901
2020.10.04,8
2020.10.05,249
2020.10.06,266
2020.10.07,739
2020.10.08,563
2020.10.09,858
2020.10.10,770
2020.10.11,1067
2020.10.12,1172
2020.10.13,559
2020.10.14,1067
2020.10.15,413
2020.10.16,569
2020.10.17,1031
2020.10.18,687
2020.10.19,415
2020.10.20,790
2020.10.21,899
2020.10.22,571
2020.10.23,707
2020.10.24,553
2020.10.25,900
2020.10.26,429
2020.10.27,1106
2020.10.28,1046
2020.10.29,139
2020.10.30,1125
2020.10.31,1061
2020.11.01,1003
2020.11.02,303
2020.11.03,747
2020.11.04,538
2020.11.05,433
2020.11.06,1160
2020.11.07,326
2020.11.08,254
2020.11.09,198
2020.11.10,92
2020.11.11,279
2020.11.12,417
2020.11.13,528
2020.11.14,549
2020.11.15,460
2020.11.16,542
2020.11.17,483
2020.11.18,187
2020.11.19,766
2020.11.20,68
2020.11.21,863
2020.11.22,1116
2020.11.23,93
2020.11.24,1147
2020.11.25,1026
2020.11.26,1144
2020.11.27,239
2020.11.28,961
2020.11.29,347
2020.11.30,190
2020.12.01,1034
2020.12.02,514
2020.12.03,234
2020.12.04,855
2020.12.05,465
2020.12.06,189
2020.12.07,344
2020.12.08,333
2020.12.09,850
2020.12.10,1170
2020.12.11,975
2020.12.12,1109
2020.12.13,1160
2020.12.14,1002
2020.12.15,419
2020.12.16,59
2020.12.17,779
2020.12.18,610
2020.12.19,738
2020.12.20,324
2020.12.21,613
2020.12.22,475
2020.12.23,494
2020.12.24,304
2020.12.25,236
2020.12.26,577
2020.12.27,328
2020.12.28,265
2020.12.29,1190
2020.12.30,532
2020.12.31,221
2021.01.01,64
2021.01.02,606
2021.01.03,187
2021.01.04,460
2021.01.05,274
2021.01.06,503
2021.01.07,983
2021.01.08,698
2021.01.09,1000
2021.01.10,1124
2021.01.11,923
2021.01.12,725
2021.01.13,137
2021.01.14,1032
2021.01.15,1118
2021.01.16,1141
2021.01.17,637
2021.01.18,716
2021.01.19,710
2021.01.20,803
2021.01.21,262
2021.01.22,384
2021.01.23,1194
2021.01.24,525
2021.01.25,404
2021.01.26,1048
2021.01.27,1019
2021.01.28,770
2021.01.29,634
2021.01.30,221
2021.01.31,815
2021.02.01,296
2021.02.02,345
2021.02.03,265
2021.02.04,875
2021.02.05,77
2021.02.06,583
2021.02.07,677
2021.02.08,148
2021.02.09,197
2021.02.10,974
2021.02.11,456
2021.02.12,717
2021.02.13,209
2021.02.14,363
2021.02.15,227
2021.02.16,909
2021.02.17,485
2021.02.18,662
2021.02.19,342
2021.02.20,1131
2021.02.21,410
2021.02.22,145
2021.02.23,488
2021.02.24,1041
2021.02.25,1117
2021.02.26,43
2021.02.27,180
2021.02.28,660
2021.03.01,546
2021.03.02,380
2021.03.03,895
2021.03.04,199
2021.03.05,535
2021.03.06,694
2021.03.07,812
2021.03.08,152
2021.03.09,877
2021.03.10,691
2021.03.11,430
2021.03.12,35
2021.03.13,147
2021.03.14,76
2021.03.15,803
2021.03.16,144
2021.03.17,923
2021.03.18,587
2021.03.19,337
2021.03.20,1162
2021.03.21,572
2021.03.22,1073
2021.03.23,248
2021.03.24,612
2021.03.25,238
2021.03.26,509
2021.03.27,502
2021.03.28,856
2021.03.29,607
2021.03.30,438
2021.03.31,525
2021.04.01,711
2021.04.02,257
2021.04.03,1190
2021.04.04,332
2021.04.05,721
2021.04.06,647
2021.04.07,788
2021.04.08,1165
2021.04.09,803
2021.04.10,442
2021.04.11,623
2021.04.12,780
2021.04.13,824
2021.04.14,631
2021.04.15,563
2021.04.16,739
2021.04.17,679
2021.04.18,988
2021.04.19,721
2021.04.20,871
2021.04.21,361
2021.04.22,674
2021.04.23,1043
2021.04.24,701
2021.04.25,982
2021.04.26,603
2021.04.27,95
2021.04.28,947
2021.04.29,617
2021.04.30,430
2021.05.01,1188
2021.05.02,1115
2021.05.03,720
2021.05.04,396
2021.05.05,54
2021.05.06,1033
2021.05.07,263
2021.05.08,729
2021.05.09,159
2021.05.10,272
2021.05.11,627
2021.05.12,187
2021.05.13,1018
2021.05.14,220
2021.05.15,721
2021.05.16,545
2021.05.17,220
2021.05.18,531
2021.05.19,738
2021.05.20,578
2021.05.21,604
2021.05.22,49
2021.05.23,299
2021.05.24,556
2021.05.25,534
2021.05.26,203
2021.05.27,741
2021.05.28,938
2021.05.29,1013
2021.05.30,1079
2021.05.31,218
2021.06.01,1198
2021.06.02,782
2021.06.03,60
2021.06.04,59
2021.06.05,528
2021.06.06,561
2021.06.07,33
2021.06.08,390
2021.06.09,375
2021.06.10,666
2021.06.11,58
2021.06.12,60
2021.06.13,113
2021.06.14,610
2021.06.15,742
2021.06.16,605
2021.06.17,674
2021.06.18,318
2021.06.19,666
2021.06.20,346
2021.06.21,849
2021.06.22,1024
2021.06.23,362
2021.06.24,608
2021.06.25,132
2021.06.26,898
2021.06.27,785
2021.06.28,590
2021.06.29,348
2021.06.30,375
\ No newline at end of file
from statsmodels.tsa.arima.model import ARIMAResults
import pandas as pd
from datetime import datetime, timedelta
model = ARIMAResults.load('component_3/no_of_vehicles.pkl')
def get_traffic_next_week():
no_of_days = 7
df = pd.read_csv('component_3/data.csv', index_col='Date', parse_dates=True)
df = df.dropna()
today = datetime.now()
n_days = today + timedelta(days=no_of_days)
index_future_dates = pd.date_range(start=today.strftime("%Y.%m.%d"), end=n_days.strftime("%Y.%m.%d"))
# print(index_future_dates)
pred = model.predict(start=len(df), end=len(df) + no_of_days,
typ='levels').rename('ARIMA Predictions')
# print(comp_pred)
pred.index = index_future_dates
output_value = []
for x in range(len(pred)):
output_value.append(round(pred[x], 2))
return output_value
# print(get_waiting_time())
import cv2
import torch
import time
import easyocr
import json
import random
import os
model = torch.hub.load('ultralytics/yolov5', 'custom', path='component_3/best_t.pt')
def get_number_plate():
# cap = cv2.VideoCapture(0) # from webcam
# print('start reading video')
# cap = cv2.VideoCapture('test_data/test.mp4') # from mp4 file
# ret, frame = cap.read()
sample_imgs = os.listdir('component_3/sample_data')
frame = cv2.imread('component_3/sample_data/' + str(random.choice(sample_imgs)))
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
result = model(image)
json_string = result.pandas().xyxy[0].to_json(orient='records')
json_obj = json.loads(json_string)
print(type(json_obj))
cropped_imgs = []
number_plate_text = 'None'
for i in json_obj:
print(i)
x = int(i["xmin"])
y = int(i["ymin"])
w = int(i["xmax"])
h = int(i["ymax"])
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2)
crop_img = image[y:y + h, x:x + w]
cropped_imgs.append(crop_img)
for cropped_img in cropped_imgs:
cv2.imwrite('save.png', cropped_img)
try:
reader = easyocr.Reader(['en'])
result = reader.readtext('save.png')
for i in result:
print(i[1])
if result[0][1] is not None:
number_plate_text = result[0][1]
else:
print('not readable by ocr')
number_plate_text = 'None'
except:
print('not readable by ocr')
number_plate_text = 'None'
print(number_plate_text)
return number_plate_text
# get_number_plate()
import cv2
import mediapipe as mp
import numpy as np
import os
import random
mp_drawing = mp.solutions.drawing_utils
mp_pose = mp.solutions.pose
mp_drawing = mp.solutions.drawing_utils
mp_holistic = mp.solutions.holistic
mp_pose = mp.solutions.pose
mp_drawing.DrawingSpec(color=(0, 0, 255), thickness=2, circle_radius=2)
def calculate_angle(a, b, c):
a = np.array(a) # First
b = np.array(b) # Mid
c = np.array(c) # End
radians = np.arctan2(c[1] - b[1], c[0] - b[0]) - np.arctan2(a[1] - b[1], a[0] - b[0])
angle = np.abs(radians * 180.0 / np.pi)
if angle > 180.0:
angle = 360 - angle
return angle
def get_human_thred():
cap = cv2.VideoCapture(0)
## Setup mediapipe instance
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
while cap.isOpened():
ret, frame = cap.read()
# Recolor image to RGB
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image.flags.writeable = False
# Make detection
results = pose.process(image)
# Recolor back to BGR
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# Extract landmarks
try:
landmarks = results.pose_landmarks.landmark
# Get coordinates
shoulder = [landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].x,
landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].y]
elbow = [landmarks[mp_pose.PoseLandmark.LEFT_ELBOW.value].x,
landmarks[mp_pose.PoseLandmark.LEFT_ELBOW.value].y]
wrist = [landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x,
landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y]
# Calculate angle
angle = calculate_angle(shoulder, elbow, wrist)
# Visualize angle
cv2.putText(image, str(angle),
tuple(np.multiply(elbow, [640, 480]).astype(int)),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2, cv2.LINE_AA
)
except:
pass
# Render detections
mp_drawing.draw_landmarks(image, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
mp_drawing.DrawingSpec(color=(245, 117, 66), thickness=2, circle_radius=2),
mp_drawing.DrawingSpec(color=(245, 66, 230), thickness=2, circle_radius=2)
)
cv2.imshow('Mediapipe Feed', image)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
def get_human_thred_temp():
with mp_pose.Pose(min_detection_confidence=0.5, min_tracking_confidence=0.5) as pose:
sample_imgs = os.listdir('component_4/sample_data')
frame = cv2.imread('component_4/sample_data/' + str(random.choice(sample_imgs)))
# Recolor image to RGB
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image.flags.writeable = False
# Make detection
results = pose.process(image)
# Recolor back to BGR
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# Extract landmarks
try:
landmarks = results.pose_landmarks.landmark
# Get coordinates
shoulder = [landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].x,
landmarks[mp_pose.PoseLandmark.LEFT_SHOULDER.value].y]
elbow = [landmarks[mp_pose.PoseLandmark.LEFT_ELBOW.value].x,
landmarks[mp_pose.PoseLandmark.LEFT_ELBOW.value].y]
wrist = [landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].x,
landmarks[mp_pose.PoseLandmark.LEFT_WRIST.value].y]
# Calculate angle
angle = calculate_angle(shoulder, elbow, wrist)
if angle > 60:
return True
else:
return False
except:
return False
pip install scikit-learn opencv-python mediapipe torch torchvision torchaudio statsmodels pmdarima
pip install opencv-python==4.5.5.64
save.png

129 KB

test.jpg

141 KB

from flask import Flask, request
from flask_cors import CORS
import json
app = Flask(__name__)
CORS(app)
@app.route('/slot_availability', methods=['GET', 'POST'])
def slot_availability():
return_str = '{ "1" : 0, "2" : 1,"3" : 0,"4" : 1,"5" : 1,"6" : 1,"7" : 0,"8" : 1,"9" : 0,"10" : 0, }'
return json.loads(return_str)
@app.route('/parking_violation', methods=['GET', 'POST'])
def parking_violation():
return_str = ' { "status" : 1" }'
return json.loads(return_str)
@app.route('/enternce', methods=['GET', 'POST'])
def enternce():
return_str = '{ "number_plate" : "KS-9908", "type" : "car" }'
return json.loads(return_str)
@app.route('/threat', methods=['GET', 'POST'])
def threat():
return_str = '{ "status" : 1 }'
return json.loads(return_str)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5000, debug=True)
File added
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