Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd7939a

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in dfa4e56 according to the output from Autopep8. Details: https://app.deepsource.com/gh/avinashkranjan/Amazing-Python-Scripts/transform/1802ca23-2633-4956-b0db-5befb7c6886b/
1 parent dfa4e56 commit bd7939a

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

‎Flask_Apis/Image_recognition_from_File_format.py‎

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import numpy as np
2-
from flask import Flask, request, jsonify, render_template,json
2+
from flask import Flask, request, jsonify, render_template,json
33
import cv2
44
from skimage.metrics import structural_similarity as ssim
55

66

7-
87
app = Flask(__name__)
98

10-
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
9+
face_cascade = cv2.CascadeClassifier(
10+
cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
11+
1112

1213
@app.route('/')
1314
def home():
14-
return jsonify({'message':'Welcome to Flask Apis'})
15+
return jsonify({'message': 'Welcome to Flask Apis'})
16+
1517

16-
@app.route('/image_Compare',methods=['POST'])
18+
@app.route('/image_Compare',methods=['POST'])
1719
def predict():
1820
file1 = request.files['file1']
1921
file2 = request.files['file2']
2022

2123
# Read the images using OpenCV
22-
img1 = cv2.imdecode(np.frombuffer(file1.read(), np.uint8), cv2.IMREAD_COLOR)
23-
img2 = cv2.imdecode(np.frombuffer(file2.read(), np.uint8), cv2.IMREAD_COLOR)
24+
img1 = cv2.imdecode(np.frombuffer(
25+
file1.read(), np.uint8), cv2.IMREAD_COLOR)
26+
img2 = cv2.imdecode(np.frombuffer(
27+
file2.read(), np.uint8), cv2.IMREAD_COLOR)
2428

2529
# Resize the images to 256x256 pixels
2630
img1 = cv2.resize(img1, (256, 256))
@@ -37,25 +41,30 @@ def predict():
3741
similarity_percentage = score * 100
3842

3943
# Return the similarity percentage in a JSON response
40-
return jsonify({'similarity_percentage': similarity_percentage})
44+
return jsonify({'similarity_percentage': similarity_percentage})
4145

42-
@app.route('/face_recognize',methods=['POST'])
46+
47+
@app.route('/face_recognize', methods=['POST'])
4348
def predictface():
44-
# Get the uploaded files from the request
49+
# Get the uploaded files from the request
4550
file1 = request.files['file1']
4651
file2 = request.files['file2']
4752

4853
# Read the images using OpenCV directly from the request files
49-
img1 = cv2.imdecode(np.frombuffer(file1.read(), np.uint8), cv2.IMREAD_COLOR)
50-
img2 = cv2.imdecode(np.frombuffer(file2.read(), np.uint8), cv2.IMREAD_COLOR)
54+
img1 = cv2.imdecode(np.frombuffer(
55+
file1.read(), np.uint8), cv2.IMREAD_COLOR)
56+
img2 = cv2.imdecode(np.frombuffer(
57+
file2.read(), np.uint8), cv2.IMREAD_COLOR)
5158

5259
# Convert the images to grayscale
5360
gray_img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
5461
gray_img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
5562

5663
# Detect faces in the images
57-
faces1 = face_cascade.detectMultiScale(gray_img1, scaleFactor=1.1, minNeighbors=5)
58-
faces2 = face_cascade.detectMultiScale(gray_img2, scaleFactor=1.1, minNeighbors=5)
64+
faces1 = face_cascade.detectMultiScale(
65+
gray_img1, scaleFactor=1.1, minNeighbors=5)
66+
faces2 = face_cascade.detectMultiScale(
67+
gray_img2, scaleFactor=1.1, minNeighbors=5)
5968

6069
# Compare only the first detected face in each image
6170
if len(faces1) > 0 and len(faces2) > 0:
@@ -81,5 +90,6 @@ def predictface():
8190
else:
8291
return jsonify({'similarity_percentage': 'Could not detect faces in both images.'})
8392

93+
8494
if __name__ == '__main__':
85-
app.run(debug=True)
95+
app.run(debug=True)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /