Skip to content

Commit

Permalink
upload image and opencv
Browse files Browse the repository at this point in the history
  • Loading branch information
aadeshere1 committed Oct 16, 2017
1 parent 480dffc commit dcecc85
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 1 deletion.
41 changes: 40 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
from flask_security import Security, SQLAlchemyUserDatastore, UserMixin, RoleMixin, login_required
from flask_mail import Mail
import os
import numpy as np
import cv2


mail = Mail()
app = Flask(__name__)

APP_ROOT = os.path.dirname(os.path.abspath(__file__))
app.config.update(
DEBUG=True,
MAIL_SERVER='smtp.gmail.com',
Expand Down Expand Up @@ -81,5 +84,41 @@ def post_user():
db.session.commit()
return redirect(url_for('index'))

@app.route('/upload')
def uploadForm():
return render_template('upload.html')

@app.route('/upload', methods=['POST'])
def upload():
target = os.path.join(APP_ROOT, 'images/')
cvTarget = os.path.join(APP_ROOT, 'manipulated/')
print(target)

if not os.path.isdir(target):
os.mkdir(target)

if not os.path.isdir(cvTarget):
os.mkdir(cvTarget)


file = request.files['file']
print(file.filename)
destination = "/".join([target, file.filename])
file.save(destination)
ref = cv2.imread(destination)
img = cv2.cvtColor(ref, cv2.COLOR_RGB2GRAY)
cv2.imwrite(img, cvTarget, 'jpg')
return render_template('complete.html')

#for file in request.files.getlist("file"):
# print(file)
# filename = file.filename
# destination = "/".join([target, filename])
# print(destination)
# file.save(destination)
# print("removing" + destination)
# os.remove(destination)
#return render_template('complete.html')

if __name__ == "__main__":
app.run()
Binary file added grey.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/b.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/filmster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions templates/complete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<head></head>
<body>
upload complete
</body>
</html>
12 changes: 12 additions & 0 deletions templates/upload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
<title>Upload your files</title>
</head>
<body>
<h1>File uploader</h1>
<form id="upload-form" action="{{url_for('upload')}}" method="POST" enctype="multipart/form-data">
<input type="file" name="file" accept="image/*" >
<input type="submit" value="Process it">
</form>
</body>
</html>

0 comments on commit dcecc85

Please sign in to comment.