Browse Source

Added features

-report system
-started public transit
-started openpose(not necessary)
old
Yiğit Çolakoğlu 6 years ago
parent
commit
3429e3a8d1
19 changed files with 206039 additions and 0 deletions
  1. +249
    -0
      MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java
  2. +9
    -0
      MyCity/app/src/main/res/drawable-v24/denunciation.xml
  3. +9
    -0
      MyCity/app/src/main/res/drawable-v24/warning.xml
  4. +34
    -0
      MyCity/app/src/main/res/layout/fragment_denunciation.xml
  5. +35
    -0
      MyCity/app/src/main/res/layout/popup_confirmation.xml
  6. BIN
      server_side/api/modules/__pycache__/denunciation.cpython-37.pyc
  7. BIN
      server_side/api/modules/__pycache__/navigation.cpython-37.pyc
  8. +57185
    -0
      server_side/api/modules/databases/bus.json
  9. +148267
    -0
      server_side/api/modules/databases/json
  10. +28
    -0
      server_side/api/modules/denunciation.py
  11. +63
    -0
      server_side/api/modules/navigation.py
  12. +60
    -0
      smart_home/.gitignore
  13. BIN
      smart_home/Output-Keypoints.jpg
  14. BIN
      smart_home/Output-Skeleton.jpg
  15. +85
    -0
      smart_home/pose_detector.py
  16. BIN
      smart_home/single.jpeg
  17. BIN
      smart_home/single.jpg
  18. BIN
      smart_home/single.png
  19. +15
    -0
      smart_home/smart_home.iml

+ 249
- 0
MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java View File

@ -0,0 +1,249 @@
package gq.yigit.mycity;
import android.Manifest;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Base64;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import gq.yigit.mycity.tools.FileActions;
import gq.yigit.mycity.tools.WebRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import static android.app.Activity.RESULT_OK;
public class DenunciationFragment extends Fragment implements WebRequest.responseListener {
private OnFragmentInteractionListener mListener;
private int reps = 0;
private String url;
private DenunciationFragment activity;
private Spinner spinner;
private String emergency;
private Button submit;
private EditText note;
private Bitmap img;
private ImageButton img_button;
private static final int CAMERA_REQUEST = 1888;
public DenunciationFragment() {
}
public static DenunciationFragment newInstance(String param1, String param2) {
DenunciationFragment fragment = new DenunciationFragment();
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_denunciation, container, false);
FileActions file_manager = new FileActions();
url = file_manager.readFromFile(getContext(),"server.config").trim();
activity=this;
submit = rootView.findViewById(R.id.denunciation_submit);
note = (EditText) rootView.findViewById(R.id.denunciation_text);
img_button= rootView.findViewById(R.id.denunciation_photo);
spinner = rootView.findViewById(R.id.denunciation_spinner);
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
img_button.setEnabled(false);
ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0);
}
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
HashMap<String,String> args = new HashMap<>();
try {
args.put("id", MainActivity.userData.getString("id"));
}catch (JSONException e){}
args.put("emergency",emergency);
args.put("note",note.getText().toString());
args.put("accepted","false");
if(img != null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
img.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
args.put("photo", encoded);
}else{
args.put("photo", "null");
}
WebRequest request = new WebRequest(url+"/denunciation",false,args);
request.addListener(activity);
request.execute();
}
});
img_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
ArrayAdapter<String> adapter;
final List<String> list = new ArrayList<String>();
list.add("Please Select...");
list.add("Ambulance");
list.add("Police");
list.add("Fire");
adapter = new ArrayAdapter<String>(getContext(),
android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
Log.i("[INFO]",String.valueOf(position));
if(position>0) {emergency = list.get(position);} }
@Override
public void onNothingSelected(AdapterView<?> parentView) {
}
});
return rootView;
}
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
}
}
@Override
public void onDetach() {
super.onDetach();
mListener = null;
}
public interface OnFragmentInteractionListener {
void onFragmentInteraction(Uri uri);
}
public void receivedResponse(boolean success, String response) {
try {
JSONObject received = new JSONObject(response);
if (reps % 2 == 0) {
if ((boolean) received.get("success")) {
Toast.makeText(getContext(), "Success", Toast.LENGTH_SHORT).show();
} else {
reps++;
final Dialog dialog = new Dialog(getContext());
dialog.setContentView(R.layout.popup_confirmation);
Button dialogButton = (Button) dialog.findViewById(R.id.confirm_button);
((TextView)dialog.findViewById(R.id.confirm_text)).setText("If this alert is wrong, you will receive a penalty of " + received.getString("penalty") +"$");
dialogButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
HashMap<String,String> args = new HashMap<>();
try {
args.put("id", MainActivity.userData.getString("id"));
}catch (JSONException e){}
args.put("emergency",emergency);
args.put("note",note.getText().toString());
if(img != null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
img.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
args.put("photo", encoded);
}else{
args.put("photo", "null");
}
args.put("accepted","true");
WebRequest requestConfirm = new WebRequest(url+"/denunciation",false,args);
requestConfirm.addListener(activity);
requestConfirm.execute();
}
});
dialog.show();
}
}else{
reps ++;
if ((boolean) received.get("success")) {
Toast.makeText(getContext(), "Success", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "An error occured", Toast.LENGTH_SHORT).show();
}
}
} catch (JSONException e) { }
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == 0) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {
img_button.setEnabled(true);
}
}
}
}

+ 9
- 0
MyCity/app/src/main/res/drawable-v24/denunciation.xml View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="512"
android:viewportHeight="512"
android:width="512dp"
android:height="512dp">
<path
android:pathData="M507.494 426.066L282.864 53.537c-5.677 -9.415 -15.87 -15.172 -26.865 -15.172c-10.995 0 -21.188 5.756 -26.865 15.172L4.506 426.066c-5.842 9.689 -6.015 21.774 -0.451 31.625c5.564 9.852 16.001 15.944 27.315 15.944h449.259c11.314 0 21.751 -6.093 27.315 -15.944C513.508 447.839 513.336 435.755 507.494 426.066zM256.167 167.227c12.901 0 23.817 7.278 23.817 20.178c0 39.363 -4.631 95.929 -4.631 135.292c0 10.255 -11.247 14.554 -19.186 14.554c-10.584 0 -19.516 -4.3 -19.516 -14.554c0 -39.363 -4.63 -95.929 -4.63 -135.292C232.021 174.505 242.605 167.227 256.167 167.227zM256.498 411.018c-14.554 0 -25.471 -11.908 -25.471 -25.47c0 -13.893 10.916 -25.47 25.471 -25.47c13.562 0 25.14 11.577 25.14 25.47C281.638 399.11 270.06 411.018 256.498 411.018z"
android:fillColor="#000000" />
</vector>

+ 9
- 0
MyCity/app/src/main/res/drawable-v24/warning.xml View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:aapt="http://schemas.android.com/aapt"
android:viewportWidth="286.054"
android:viewportHeight="286.054"
android:width="286.054dp"
android:height="286.054dp">
<path
android:pathData="M143.027 0C64.04 0 0 64.04 0 143.027c0 78.996 64.04 143.027 143.027 143.027c78.996 0 143.027 -64.022 143.027 -143.027C286.054 64.04 222.022 0 143.027 0zM143.027 259.236c-64.183 0 -116.209 -52.026 -116.209 -116.209S78.844 26.818 143.027 26.818s116.209 52.026 116.209 116.209S207.21 259.236 143.027 259.236zM143.036 62.726c-10.244 0 -17.995 5.346 -17.995 13.981v79.201c0 8.644 7.75 13.972 17.995 13.972c9.994 0 17.995 -5.551 17.995 -13.972V76.707C161.03 68.277 153.03 62.726 143.036 62.726zM143.036 187.723c-9.842 0 -17.852 8.01 -17.852 17.86c0 9.833 8.01 17.843 17.852 17.843s17.843 -8.01 17.843 -17.843C160.878 195.732 152.878 187.723 143.036 187.723z"
android:fillColor="#E2574C" />
</vector>

+ 34
- 0
MyCity/app/src/main/res/layout/fragment_denunciation.xml View File

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DenunciationFragment" android:orientation="vertical" android:layout_marginTop="60dp">
<!-- TODO: Update blank fragment layout -->
<Spinner
android:layout_width="match_parent"
android:layout_height="39dp" android:id="@+id/denunciation_spinner"/>
<EditText
android:layout_width="match_parent"
android:layout_height="221dp"
android:inputType="textMultiLine"
android:ems="10"
android:id="@+id/denunciation_text"
android:layout_marginTop="8dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp">
<ImageButton
android:src="@drawable/ic_menu_camera"
android:layout_width="153dp"
android:layout_height="wrap_content" android:id="@+id/denunciation_photo" android:layout_weight="1"/>
<Button
android:text="Submit"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/denunciation_submit" android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>

+ 35
- 0
MyCity/app/src/main/res/layout/popup_confirmation.xml View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="If this alert is wrong, you will receive a penalty of "
android:layout_width="244dp"
android:layout_height="wrap_content"
android:id="@+id/confirm_text"
android:textStyle="normal|bold"
android:textSize="18sp"
android:layout_alignParentTop="true"
android:layout_marginTop="193dp" android:layout_centerHorizontal="true" android:textColor="#000000"/>
<Button
android:id="@+id/confirm_button"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="OK"
android:paddingRight="5dp"
android:textSize="18sp"
style="@android:style/Widget.Button"
tools:ignore="RtlHardcoded,RtlSymmetry"
android:layout_centerHorizontal="true" android:layout_alignParentBottom="true"
android:layout_marginBottom="211dp" android:background="@android:color/holo_red_dark"/>
<ImageView
android:layout_width="191dp"
android:layout_height="181dp" app:srcCompat="@drawable/warning"
android:layout_centerHorizontal="true" android:id="@+id/imageView"
android:layout_alignParentTop="true"/>
</RelativeLayout>

BIN
server_side/api/modules/__pycache__/denunciation.cpython-37.pyc View File


BIN
server_side/api/modules/__pycache__/navigation.cpython-37.pyc View File


+ 57185
- 0
server_side/api/modules/databases/bus.json
File diff suppressed because it is too large
View File


+ 148267
- 0
server_side/api/modules/databases/json
File diff suppressed because it is too large
View File


+ 28
- 0
server_side/api/modules/denunciation.py View File

@ -0,0 +1,28 @@
from flask import Flask, request
from flask_restful import Resource, Api, abort
import json
import os
app = Flask(__name__)
api = Api(app)
db_path = os.path.join(app.root_path, 'databases', 'users.json')
with open(db_path, 'r') as f:
users = json.load(f)
class Alert(Resource):
def post(self):
args = request.form
username= ""
for user in users:
if users[user]["id"] == args["id"]:
username=user
break
trust = int(users[username]["trustability"])
if trust > 20 or args["accepted"] == "true":
return {"success":True}
else:
return {"success":False,"penalty":"{}".format(100*(20-trust))}

+ 63
- 0
server_side/api/modules/navigation.py View File

@ -0,0 +1,63 @@
from flask import Flask, request
from flask_restful import Resource, Api, abort
import requests
import json
app = Flask( __name__ )
api = Api( app )
bus_data = open("databases/bus.json","a")
def sendRequest( url, raw ):
headers = {
"User-Agent": "EGO Genel Mudurlugu-EGO Cepte-3.1.0 GT-I9500 7.1.2",
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": "0" }
headers[ "Content-Length" ] = str( len( raw ) )
r = requests.post( url, headers=headers, data=raw )
content = r.content.decode( "cp1252" )
content = content.replace( "Ý", "I" )
content = content.replace( "ý", "i" )
content = content.replace( "ð", "g" )
content = content.replace( "þ", "s" )
content = content.replace( "Þ", "S" )
return content
conn1 = sendRequest(
'http://88.255.141.70/mbl/android/connect.asp?SID=0.9672804113380772&VER=3.1.0&LAN=tr&UID=%7BACB78701' \
'-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Connect',
"UID=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&UPS=TRUE" )
conn2 = sendRequest(
'http://88.255.141.66/mbl/android/connect.asp?SID=0.6654049014198404&VER=3.1.0&LAN=tr&UID=%7BACB78701' \
'-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Start', "" )
hatlar = sendRequest( 'http://88.255.141.66/mbl/android/action.asp?SID=0.8328642811845514&VER=3.1.0&LAN=tr&UID'
'=%7BACB78701-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Hatlar', "QUERY=" )
hatlar = hatlar.replace( "'", '"' )
hatlar = json.loads( hatlar )
class Transit( Resource ):
def post( self ):
args = request.form
durak = sendRequest(
"http://88.255.141.66/mbl/android/service.asp?SID=0.09912588645045828&VER=3.1.0&LAN=tr&UID=%7BACB78701" \
"-2727-4E9A-AE62-28491D671A7D%7D-130570234&FNC=Otobusler", "DURAK=" + str( args[ "stop" ] ) )
durak = durak.replace( "'", '"' )
durak = json.loads( durak )
return [durak,hatlar]
if __name__ == '__main__':
api.add_resource( Transit, '/transit', '/transit/' )
app.run( host='0.0.0.0', port=5000 )

+ 60
- 0
smart_home/.gitignore View File

@ -0,0 +1,60 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/dictionaries
.idea/**/shelf
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
cmake-build-release/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
face/*
hand/*
pose/*
cameraParameters/*
cameraParameters/*/*

BIN
smart_home/Output-Keypoints.jpg View File

Before After
Width: 3000  |  Height: 2000  |  Size: 946 KiB

BIN
smart_home/Output-Skeleton.jpg View File

Before After
Width: 3000  |  Height: 2000  |  Size: 974 KiB

+ 85
- 0
smart_home/pose_detector.py View File

@ -0,0 +1,85 @@
import cv2
import time
import numpy as np
MODE = "MPI"
if MODE is "COCO":
protoFile = "pose/coco/pose_deploy_linevec.prototxt"
weightsFile = "pose/coco/pose_iter_440000.caffemodel"
nPoints = 18
POSE_PAIRS = [ [1,0],[1,2],[1,5],[2,3],[3,4],[5,6],[6,7],[1,8],[8,9],[9,10],[1,11],[11,12],[12,13],[0,14],[0,15],[14,16],[15,17]]
elif MODE is "MPI" :
protoFile = "pose/mpi/pose_deploy_linevec_faster_4_stages.prototxt"
weightsFile = "pose/mpi/pose_iter_160000.caffemodel"
nPoints = 15
POSE_PAIRS = [[0,1], [1,2], [2,3], [3,4], [1,5], [5,6], [6,7], [1,14], [14,8], [8,9], [9,10], [14,11], [11,12], [12,13] ]
frame = cv2.imread("single.jpeg")
frameCopy = np.copy(frame)
frameWidth = frame.shape[1]
frameHeight = frame.shape[0]
threshold = 0.2
net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)
t = time.time()
# input image dimensions for the network
inWidth = 368
inHeight = 368
inpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight),
(0, 0, 0), swapRB=False, crop=False)
net.setInput(inpBlob)
output = net.forward()
print("time taken by network : {:.3f}".format(time.time() - t))
H = output.shape[2]
W = output.shape[3]
# Empty list to store the detected keypoints
points = []
for i in range(nPoints):
# confidence map of corresponding body's part.
probMap = output[0, i, :, :]
# Find global maxima of the probMap.
minVal, prob, minLoc, point = cv2.minMaxLoc(probMap)
# Scale the point to fit on the original image
x = (frameWidth * point[0]) / W
y = (frameHeight * point[1]) / H
if prob > threshold :
cv2.circle(frameCopy, (int(x), int(y)), 8, (0, 255, 255), thickness=-1, lineType=cv2.FILLED)
cv2.putText(frameCopy, "{}".format(i), (int(x), int(y)), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2, lineType=cv2.LINE_AA)
# Add the point to the list if the probability is greater than the threshold
points.append((int(x), int(y)))
else :
points.append(None)
# Draw Skeleton
for pair in POSE_PAIRS:
partA = pair[0]
partB = pair[1]
if points[partA] and points[partB]:
cv2.line(frame, points[partA], points[partB], (0, 255, 255), 2)
cv2.circle(frame, points[partA], 8, (0, 0, 255), thickness=-1, lineType=cv2.FILLED)
cv2.imshow('Output-Keypoints', cv2.resize(frameCopy,(900,900)))
cv2.imshow('Output-Skeleton', cv2.resize(frame,(600,900)))
cv2.imwrite('Output-Keypoints.jpg', frameCopy)
cv2.imwrite('Output-Skeleton.jpg', frame)
print("Total time taken : {:.3f}".format(time.time() - t))
cv2.waitKey(0)

BIN
smart_home/single.jpeg View File

Before After
Width: 3000  |  Height: 2000  |  Size: 548 KiB

BIN
smart_home/single.jpg View File

Before After
Width: 2000  |  Height: 1333  |  Size: 237 KiB

BIN
smart_home/single.png View File

Before After
Width: 946  |  Height: 1248  |  Size: 1018 KiB

+ 15
- 0
smart_home/smart_home.iml View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python">
<configuration sdkName="Python 3.7" />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Python 3.7 interpreter library" level="application" />
</component>
</module>

Loading…
Cancel
Save