forked from ruhyadi/YOLO3D
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import os | ||
from flask import Flask, render_template, request | ||
import cv2 | ||
import numpy as np | ||
import base64 | ||
from werkzeug.utils import secure_filename | ||
import shutil | ||
from pathlib import Path | ||
import sys | ||
import argparse | ||
|
||
from inference import detect3d | ||
|
||
FILE = Path(__file__).resolve() | ||
ROOT = FILE.parents[0] # YOLOv5 root directory | ||
if str(ROOT) not in sys.path: | ||
sys.path.append(str(ROOT)) # add ROOT to PATH | ||
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative | ||
|
||
app = Flask(__name__) | ||
|
||
UPLOAD_FOLDER = os.path.basename('static') | ||
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER | ||
|
||
@app.route("/") | ||
def start_page(): | ||
print("Start") | ||
return render_template('index.html') | ||
|
||
@app.route('/upload', methods=['POST']) | ||
def upload_file(): | ||
FILENAME = {} | ||
# get file | ||
image = request.files['image'] | ||
|
||
# save file | ||
image.save('static/image_eval.png') | ||
|
||
if 'image' in request.files: | ||
detect = True | ||
|
||
# process file | ||
detect3d( | ||
reg_weights='weights/epoch_10.pkl', | ||
model_select='resnet', | ||
source='static', | ||
calib_file='eval/camera_cal/calib_cam_to_cam.txt', | ||
save_result=True, | ||
show_result=False, | ||
output_path='static/' | ||
) | ||
|
||
# encode to base64 image | ||
with open('static/000.png', 'rb') as image_file: | ||
img_encode = base64.b64encode(image_file.read()) | ||
to_send = 'data:image/png;base64, ' + str(img_encode, 'utf-8') | ||
else: | ||
detect = False | ||
|
||
return render_template('index.html', init=True, detect=detect, image_to_show=to_send) | ||
|
||
def parse_opt(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--weights', nargs='+', type=str, default=ROOT / 'yolov5s.pt', help='model path(s)') | ||
parser.add_argument('--source', type=str, default=ROOT / 'eval/image_2', help='file/dir/URL/glob, 0 for webcam') | ||
parser.add_argument('--data', type=str, default=ROOT / 'data/coco128.yaml', help='(optional) dataset.yaml path') | ||
parser.add_argument('--imgsz', '--img', '--img-size', nargs='+', type=int, default=[640], help='inference size h,w') | ||
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') | ||
parser.add_argument('--classes', default=[0, 2, 3, 5], nargs='+', type=int, help='filter by class: --classes 0, or --classes 0 2 3') | ||
parser.add_argument('--reg_weights', type=str, default='weights/epoch_10.pkl', help='Regressor model weights') | ||
parser.add_argument('--model_select', type=str, default='resnet', help='Regressor model list: resnet, vgg, eff') | ||
parser.add_argument('--calib_file', type=str, default=ROOT / 'eval/camera_cal/calib_cam_to_cam.txt', help='Calibration file or path') | ||
parser.add_argument('--show_result', action='store_true', help='Show Results with imshow') | ||
parser.add_argument('--save_result', action='store_true', help='Save result') | ||
parser.add_argument('--output_path', type=str, default=ROOT / 'output', help='Save output pat') | ||
|
||
opt = parser.parse_args() | ||
opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand | ||
return opt | ||
|
||
|
||
if __name__ == '__main__': | ||
try: | ||
os.makedirs('static') | ||
except: | ||
print('Directory already exist!') | ||
opt = parse_opt() | ||
app.run() | ||
shutil.rmtree('static') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>YOLO3D</title> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<div class="starter-template"> | ||
<h1>3D Object Detection with YOLO</h1> | ||
<p>By Didi Ruhyadi - github.com/ruhyadi/yolo3d</p> | ||
</div> | ||
</div> | ||
|
||
<header class="navbar"> | ||
<div align="center"> | ||
<h4>Upload Image</h4> | ||
<form action="/upload" method="post" enctype="multipart/form-data" > | ||
<div align="center"> | ||
<label class="btn btn-default btn-file"> | ||
Browse Image<input type="file" name="image" style="display: none;"> | ||
</label> | ||
<input type="submit" value="Submit" class="btn btn-primary"> | ||
</div> | ||
</form> | ||
</div> | ||
|
||
</header> | ||
|
||
<div class="text-center"> | ||
{% if init %} | ||
{% if detect %} | ||
<div class="alert alert-success" style="margin-top:18px;"> | ||
Pattern <strong>Detected</strong> on Video | ||
</div> | ||
<div> | ||
<img src="{{ image_to_show }}"> | ||
</div> | ||
{% else %} | ||
<div class="alert alert-danger" style="margin-top:18px;"> | ||
No Pattern Detected | ||
</div> | ||
{% endif %} | ||
{% endif %} | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters