Skip to content

Commit

Permalink
- Update attribute sharpness_differences to sharpness_similarity
Browse files Browse the repository at this point in the history
- Update gitignore
- update index.html to include few notes

Signed-off-by: Lim Kha Shing <[email protected]>
  • Loading branch information
limkhashing committed Sep 23, 2020
1 parent dd86e36 commit 4de22f4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,6 @@ venv.bak/
# real life test data
/tests/test_data_ic_driving_passport/
/Documentation/
/sample_data/my real ic.jpg
/sample_data/fake ic.jpg
/sample_data/fake ic near.jpg
14 changes: 7 additions & 7 deletions src/face_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def compare_face(known_path, video_path, request_upload_folder_path, request_fra
is_match = None
confidences_list = []
known_face_encoding = []
sharpness_difference = None
sharpness_similarity = None

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

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

#####
# Part 4
Expand All @@ -117,7 +117,7 @@ def compare_face(known_path, video_path, request_upload_folder_path, request_fra
# and return the result as Json
#####
final_confidence = sum(confidences_list) / float(len(confidences_list))
if final_confidence >= face_match_threshold and sharpness_difference > sharpness_threshold:
if final_confidence >= face_match_threshold and sharpness_similarity > sharpness_threshold:
is_match = True
else:
is_match = False
Expand All @@ -131,18 +131,18 @@ def compare_face(known_path, video_path, request_upload_folder_path, request_fra
delete_files(request_upload_folder_path, request_frames_folder_path)

return jsonify(
get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence, sharpness_difference,
get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence, sharpness_similarity,
file_type, ocr_results))


def get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence, sharpness_difference,
def get_json_response(face_found_in_image, face_found_in_video, is_match, final_confidence, sharpness_similarity,
file_type, ocr_results):
return {
"face_found_in_image": face_found_in_image,
"face_found_in_video": face_found_in_video,
"is_match": is_match,
"confidence": final_confidence,
"sharpness_difference": sharpness_difference,
"sharpness_similarity": sharpness_similarity,
"file_type": file_type,
"ocr_results": ocr_results
}
45 changes: 26 additions & 19 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,37 @@
<title>Face Matching</title>
<link rel="shortcut icon" type="image/x-icon" href="{{ url_for('static', filename='favicon.png') }}">
</head>
<body>
<body>

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

<p> Upload a video to compare:
<input type="file" name="unknown"></p>
<p> Upload a video to compare:
<input type="file" name="unknown"></p>

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

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

<p> Please specify the threshold to consider the face matching is pass. By default is 0.80 </p>
<input type="number" name="threshold"
min="0" max="1" step="0.01" placeholder="0.80"> <br> <br>
<p> Please specify the face match threshold to consider the face matching is pass. By default is <b> 0.80 </b>
</p>
<input type="number" name="threshold"
min="0" max="1" step="0.01" placeholder="0.80"> <br> <br>

<input type="submit" value="Compare">
</form>
</body>
<p> * On the attribute that returned from API, only both <b> sharpness_similarity </b>
and <b>confidence </b> must more than the threshold specified, then only the face matching is consider pass
</p>
<input type="submit" value="Compare">
</form>
</body>

</html>

0 comments on commit 4de22f4

Please sign in to comment.