Skip to content

Commit 4de22f4

Browse files
committed
- Update attribute sharpness_differences to sharpness_similarity
- Update gitignore - update index.html to include few notes Signed-off-by: Lim Kha Shing <kslim5703@gmail.com>
1 parent dd86e36 commit 4de22f4

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ venv.bak/
110110
# real life test data
111111
/tests/test_data_ic_driving_passport/
112112
/Documentation/
113+
/sample_data/my real ic.jpg
114+
/sample_data/fake ic.jpg
115+
/sample_data/fake ic near.jpg

src/face_processing.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def compare_face(known_path, video_path, request_upload_folder_path, request_fra
3434
is_match = None
3535
confidences_list = []
3636
known_face_encoding = []
37-
sharpness_difference = None
37+
sharpness_similarity = None
3838

3939
# Load the uploaded image file
4040
known_image = face_recognition.load_image_file(known_path)
@@ -55,7 +55,7 @@ def compare_face(known_path, video_path, request_upload_folder_path, request_fra
5555
face_image = known_image[top:bottom, left:right]
5656
cropped_face = Image.fromarray(face_image)
5757
cropped_face.save(cropped_face_path, "JPEG")
58-
sharpness_difference = calculate_sharpness(known_path, cropped_face_path)
58+
sharpness_similarity = calculate_sharpness(known_path, cropped_face_path)
5959

6060
#####
6161
# Part 2
@@ -108,7 +108,7 @@ def compare_face(known_path, video_path, request_upload_folder_path, request_fra
108108
print("Did not found face in either image or video. Can't proceed to compare with image")
109109
delete_files(request_upload_folder_path, request_frames_folder_path)
110110
return jsonify(get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence,
111-
sharpness_difference, file_type, ocr_results))
111+
sharpness_similarity, file_type, ocr_results))
112112

113113
#####
114114
# Part 4
@@ -117,7 +117,7 @@ def compare_face(known_path, video_path, request_upload_folder_path, request_fra
117117
# and return the result as Json
118118
#####
119119
final_confidence = sum(confidences_list) / float(len(confidences_list))
120-
if final_confidence >= face_match_threshold and sharpness_difference > sharpness_threshold:
120+
if final_confidence >= face_match_threshold and sharpness_similarity > sharpness_threshold:
121121
is_match = True
122122
else:
123123
is_match = False
@@ -131,18 +131,18 @@ def compare_face(known_path, video_path, request_upload_folder_path, request_fra
131131
delete_files(request_upload_folder_path, request_frames_folder_path)
132132

133133
return jsonify(
134-
get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence, sharpness_difference,
134+
get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence, sharpness_similarity,
135135
file_type, ocr_results))
136136

137137

138-
def get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence, sharpness_difference,
138+
def get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence, sharpness_similarity,
139139
file_type, ocr_results):
140140
return {
141141
"face_found_in_image": face_found_in_image,
142142
"face_found_in_video": face_found_in_video,
143143
"is_match": is_match,
144144
"confidence": final_confidence,
145-
"sharpness_difference": sharpness_difference,
145+
"sharpness_similarity": sharpness_similarity,
146146
"file_type": file_type,
147147
"ocr_results": ocr_results
148148
}

templates/index.html

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,37 @@
44
<title>Face Matching</title>
55
<link rel="shortcut icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.png') }}">
66
</head>
7-
<body>
7+
<body>
88

9-
<h1>Upload a picture and a video and see if it's same person!</h1>
10-
<form method="POST" enctype="multipart/form-data" action="/api/upload">
11-
<p> Upload the first picture: <input type="file" name="known"></p>
9+
<h1>Upload a picture and a video and see if it's same person!</h1>
10+
<form method="POST" enctype="multipart/form-data" action="/api/upload">
11+
<p> Upload the first picture: <input type="file" name="known"></p>
1212

13-
<p> Upload a video to compare:
14-
<input type="file" name="unknown"></p>
13+
<p> Upload a video to compare:
14+
<input type="file" name="unknown"></p>
1515

16-
<p> You can specify the tolerance if you wish to (from 0.0 to 1.0). By default is 0.50 </p>
17-
<p> Tolerance is to measure how much distance between faces to consider it a match. Lower is more strict </p>
18-
<input type="number" name="tolerance"
19-
min="0" max="1" step="0.01" placeholder="0.50"> <br>
16+
<p> You can specify the tolerance if you wish to (from 0.0 to 1.0). By default is <b> 0.50 </b></p>
17+
<p> Tolerance is to measure how much distance between faces to consider it a match. Lower is more strict </p>
18+
<input type="number" name="tolerance"
19+
min="0" max="1" step="0.01" placeholder="0.50"> <br>
2020

21-
<p> Please specify the threshold for sharpness to consider as a valid document photo. By default is 0.60</p>
22-
<input type="number" name="sharpness"
23-
min="0" max="1" step="0.01" placeholder="0.60"> <br>
21+
<p> Please specify the sharpness threshold to consider as a valid document photo. By default is <b> 0.60 </b>
22+
</p>
23+
<p><b> Note: </b> The API will return a sharpness_similarity, which ranged from <b>0.0 (very different) </b> to
24+
<b> 1.0 (identical) </b></p>
25+
<input type="number" name="sharpness"
26+
min="0" max="1" step="0.01" placeholder="0.60"> <br>
2427

25-
<p> Please specify the threshold to consider the face matching is pass. By default is 0.80 </p>
26-
<input type="number" name="threshold"
27-
min="0" max="1" step="0.01" placeholder="0.80"> <br> <br>
28+
<p> Please specify the face match threshold to consider the face matching is pass. By default is <b> 0.80 </b>
29+
</p>
30+
<input type="number" name="threshold"
31+
min="0" max="1" step="0.01" placeholder="0.80"> <br> <br>
2832

29-
<input type="submit" value="Compare">
30-
</form>
31-
</body>
33+
<p> * On the attribute that returned from API, only both <b> sharpness_similarity </b>
34+
and <b>confidence </b> must more than the threshold specified, then only the face matching is consider pass
35+
</p>
36+
<input type="submit" value="Compare">
37+
</form>
38+
</body>
3239

3340
</html>

0 commit comments

Comments
 (0)