Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PoKai-H committed Aug 23, 2022
0 parents commit 4b98f5d
Show file tree
Hide file tree
Showing 38 changed files with 21,703 additions and 0 deletions.
Binary file added __pycache__/app.cpython-310.pyc
Binary file not shown.
75 changes: 75 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from flask import Flask,render_template, request, redirect, url_for, make_response,jsonify
from werkzeug.utils import secure_filename
import os
from skimage.metrics import structural_similarity
import imutils
import cv2
from PIL import Image


ALLOWED_EXTENSIONS = set(['png','jpg','JPG','PNG'])

def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS

app = Flask(__name__)

@app.route('/', methods=['POST','GET'])
def index():
if request.method == 'GET':
return render_template('index.html')
if request.method == 'POST':
f = request.files['file_upload']

if not (f and allowed_file(f.filename)):
return jsonify({"error": 1001, "msg": "please check yout file type (only except JPG, PNG, jpg, png files)"})

base_path = os.path.dirname(__file__)


upload_path = os.path.join(base_path, 'images/upload_image', secure_filename(f.filename))
f.save(upload_path)

uploaded_img = Image.open(upload_path).resize((250,160))

uploaded_img.save(os.path.join(base_path,'images/upload_image','tampered.jpg'))

original_img = Image.open(os.path.join(base_path,'images/origin_image','origin1.jpg')).resize((250,160))
original_img.save(os.path.join(base_path,'images/origin_image','origin1.jpg'))



origin_img = cv2.imread(os.path.join(base_path,'images/origin_image','origin1.jpg'))
upload_img = cv2.imread(os.path.join(base_path,'images/upload_image','tampered.jpg'))


original_grey = cv2.cvtColor(origin_img,cv2.COLOR_BGR2GRAY)
uploaded_grey = cv2.cvtColor(upload_img,cv2.COLOR_BGR2GRAY)

# Compute the structural similarity Index (SSIM) between the two images, ensuring that the difference image is returned
(score, diff)= structural_similarity(original_grey, uploaded_grey, full=True)
diff = (diff * 255).astype("uint8")

# Calculating threshold and contours
thresh = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)


#loop over the contours
for c in cnts:
# applying contours on image
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(origin_img, (x,y), (x+w, y+h), (0, 0, 255), 2)
cv2.rectangle(upload_img, (x,y), (x+y, y+h), (0, 0, 255), 2)

cv2.imwrite(os.path.join(base_path,'static/generated','image_original1.jpg'),origin_img)
cv2.imwrite(os.path.join(base_path,'static/generated','image_uploaded1.jpg'),upload_img)
cv2.imwrite(os.path.join(base_path,'static/generated','diff1.jpg'),diff)
cv2.imwrite(os.path.join(base_path,'static/generated','thresh1.jpg'),thresh)

return render_template('index_ok.html',pred=str(round(score*100,2))+ '%' + 'correct')


if __name__ == '__main__':
app.run(host='0.0.0.0', port=8987, debug=False)
Binary file added images/generted_image/diff.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/generted_image/diff1.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/generted_image/image_original.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/generted_image/image_original1.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/generted_image/image_uploaded.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/generted_image/image_uploaded1.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/generted_image/thresh.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/generted_image/thresh1.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/origin_image/3530348.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/origin_image/R.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/origin_image/origin.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/origin_image/origin1.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/origin_image/origin2.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/upload_image/3530348.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/upload_image/R.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/upload_image/origin.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/upload_image/origin1.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/upload_image/origin2.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/upload_image/tampered.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4b98f5d

Please sign in to comment.