Commit 69dfd171 authored by Janage Tiran Harsha Jayawardana's avatar Janage Tiran Harsha Jayawardana

Merge branch 'IT18216974' into 'master'

merge

See merge request !2
parents e0701f4b e745434d
Pipeline #5878 failed with stage
in 0 seconds
web: gunicorn app:app
\ No newline at end of file
import cv2
import numpy as np
from flask import Flask, jsonify, request
import os
app = Flask(__name__)
@app.route("/")
def indexfun():
return "welcome"
@app.route("/predict", methods=['POST'])
def predictfun():
net = cv2.dnn.readNet("yolov4-custom_2000.weights", "yolov4-custom.cfg")
file = request.files['file']
image_path = "./images/" + file.filename
file.save(image_path)
value_x = 0
value_y = 0
value_w = 0
value_h = 0
img = cv2.imread(image_path)
height, width, _ = img.shape
blob = cv2.dnn.blobFromImage(img, 1/255, (416,416), (0,0,0), swapRB=True, crop=False)
net.setInput(blob)
output_layers_names = net.getUnconnectedOutLayersNames()
layerOutputs = net.forward(output_layers_names)
boxes = []
class_ids = []
confidences = []
for output in layerOutputs:
for detection in output:
scores = detection[5:]
class_id = np.argmax(scores)
confidence = scores[class_id]
if confidence > 0.5:
center_x = int(detection[0]*width)
center_y = int(detection[1]*height)
w = int(detection[2]*width)
h = int(detection[3]*height)
x = int(center_x - w/2)
y = int(center_y - h/2)
boxes.append([x, y, w, h])
confidences.append((float(confidence)))
class_ids.append(class_id)
indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.5, 0.4)
if(len(boxes)>0):
for i in indexes.flatten():
x, y, w, h = boxes[i]
#[70, 69, 116, 194]
value_x = x
value_y = y
value_w = x+w
value_h = y+h
os.remove(image_path)
return jsonify({
'detected' : 1,
'x': value_x,
'w': value_w,
'y': value_y,
'h': value_h,
})
else:
os.remove(image_path)
return jsonify({
'detected' : 0,
'x': 0,
'w': 0,
'y': 0,
'h': 0,
})
if __name__ == "__main__":
app.run(debug=True)
staircase
\ No newline at end of file
click==8.0.1
colorama==0.4.4
Flask==2.0.1
gunicorn==20.1.0
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
Werkzeug==2.0.1
opencv-contrib-python-headless
numpy
\ No newline at end of file
This diff is collapsed.
import requests
API_URL = "https://boundary-detection.herokuapp.com/predict";
files = {'file': ("images.jpg", open('images.jpg', 'rb'))}
resp = requests.post(API_URL, files=files)
data = resp.json()
print(resp.status_code)
print(data)
print(data['x'])
\ No newline at end of file
import requests
API_URL = "https://staircase-detection.herokuapp.com/predict";
files = {'file': ("1.png", open('1.png', 'rb'))}
resp = requests.post(API_URL, files=files)
data = resp.json()
print(resp.status_code)
print(data)
print(data['type'])
\ No newline at end of file
import requests
import cv2
#get x,y,w,h
API_URL = "https://boundary-detection.herokuapp.com/predict";
files = {'file': ("images.jpg", open('images.jpg', 'rb'))}
resp = requests.post(API_URL, files=files)
data = resp.json()
if(resp.status_code == 200):
x = int(data['x'])
y = int(data['y'])
w = int(data['w'])
h = int(data['h'])
img = cv2.imread('images.jpg')
img = img[y:h,x:w]
cv2.imwrite('cropped.jpg',img)
API_URL = "https://step-count.herokuapp.com/predict";
files = {'file': ('cropped.jpg',open("cropped.jpg", 'rb'))}
resp = requests.post(API_URL, files=files)
data = resp.json()
print(resp.status_code)
print(data)
print(data['steps'])
else:
print("No staircase")
\ No newline at end of file
web: gunicorn app:app
\ No newline at end of file
from flask import Flask, request, jsonify
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.image import load_img
import numpy as np
import os
app = Flask(__name__)
@app.route('/')
def indexfn():
return "<h1> Welcome </h1>"
@app.route('/predict', methods = ['POST'])
def predictfn():
class_mask = ['Staircase not detected', 'Staircase Detected']
file = request.files['file']
image_path = "./images/" + file.filename
file.save(image_path)
try:
img = load_img(image_path, target_size=(224,224))
img = np.asarray(img)
img = np.expand_dims(img, axis=0)
saved_model = load_model('vgg16_1.h5')
output = saved_model.predict(img)
pred = class_mask[np.argmax(output)]
os.remove(path=image_path)
return jsonify({'type': pred})
except BaseException as err:
return jsonify({'error': 'error at prediction'})
if __name__ == "__main__":
app.run(debug=True)
\ No newline at end of file
click==8.0.1
colorama==0.4.4
Flask==2.0.1
gunicorn==20.1.0
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
Werkzeug==2.0.1
Keras==2.4.3
tensorboard==2.5.0
tensorflow-cpu==2.5.0
numpy
Pillow==8.2.0
# PILL
\ No newline at end of file
web: gunicorn app:app
\ No newline at end of file
from flask import Flask, request, jsonify
import math
import cv2
import os
app = Flask(__name__)
@app.route("/")
def indexfun():
return "welcome"
@app.route("/predict", methods = ['POST'])
def getStepCount():
file = request.files['file']
image_path = "./images/" + file.filename
file.save(image_path)
image = cv2.imread(image_path)
gray_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
gaussian_image = cv2.GaussianBlur(gray_image,(9,9),0,0)
canny_image = cv2.Canny(gaussian_image,80,240,3)
# canny_image = cv2.Canny(gaussian_image,50,120)
output_image = cv2.cvtColor(canny_image, cv2.COLOR_GRAY2BGR)
output_image2 = cv2.cvtColor(canny_image, cv2.COLOR_GRAY2BGR)
output_image3 = cv2.cvtColor(canny_image, cv2.COLOR_GRAY2BGR)
lines = list()
lines = cv2.HoughLinesP(canny_image,1,math.pi/180,30,40,5)
for i in range(0,len(lines)):
line = lines[i][0]
cv2.line(output_image,(line[0],line[1]),(line[2],line[3]),(0,0,255),3,5)
y_values = list()
x_values = list()
# print(lines)
# print("################")
# print(lines[0][0]) #[ 25 189 167 189]
# print(lines.shape)
# remove vertical lines
for i in range(0, len(lines)):
line = lines[i][0]
#line -> [ 25 189 167 189]
#line -> y1-[1] -> 189
#line -> y2-[3] -> 189
if (abs(line[1] - line[3])) < 5:
y_values.append([line[1],line[3]])
x_values.append([line[0],line[2]])
#line -> x1-[0] -> 25
#line -> x2-[2] -> 167
if (abs(line[0] - line[2])) > 100:
y_values.append([line[1],line[3]])
x_values.append([line[0],line[2]])
# print(y_values)
# print("################")
# print(y_values[0]) #[189, 189]
for i in range(0, len(y_values)):
# y_ax -> [189, 189]
y_ax = y_values[i]
x_ax = x_values[i]
cv2.line(output_image2,(x_ax[0],y_ax[0]),(x_ax[1],y_ax[1]),(0,0,255),3,5)
# remove unwanted horizontal lines
# print(y_values)
# print("################")
# print(y_values[0][0]) #189
# # y_ax -> 189
y_ax = list()
y_ax.append(y_values[0][0])
stair_count = 0
flag = 1
for i in range(0, len(y_values)):
line = y_values[i]
#line -> [189, 189]
for j in range(0, len(y_ax)):
# y_ax -> 189
# This value will calculate with help of step height and width (15,40,60)
step_heigth_mean = 15
if (abs(y_ax[j] - line[1]) < step_heigth_mean):
flag = 0
if flag:
cv2.line(output_image3,(0,line[1]),(output_image3.shape[1],line[1]),(0,0,255),3,5)
stair_count = stair_count + 1
y_ax.append(line[1])
flag = 1
print("Stair count :"+ str(stair_count))
os.remove(image_path)
return jsonify({"steps": str(stair_count)})
if __name__ == "__main__":
app.run(debug=True)
\ No newline at end of file
click==8.0.1
colorama==0.4.4
Flask==2.0.1
gunicorn==20.1.0
itsdangerous==2.0.1
Jinja2==3.0.1
MarkupSafe==2.0.1
Werkzeug==2.0.1
opencv-contrib-python-headless
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
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