Skip to content
This repository was archived by the owner on Oct 8, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def update(self):
words.append((x, y, w, h, text))
if words:
sentences = group_words_to_sentences(words)
ss = ""
for sentence in sentences:
ss += sentence + "\n"
ss = "".join(sentence + "\n" for sentence in sentences)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TextDetectorGUI.update refactored with the following changes:

  • Use str.join() instead of for loop (use-join)

if prev_ss != ss:
self.text_label.delete(1.0, tk.END)
self.text_label.insert(tk.END, ss)
Expand Down Expand Up @@ -165,16 +163,14 @@ def save_face(self):
if name == "":
tk.messagebox.showerror("Error", "Please enter a name.")
return
filename = os.path.join("./known_faces/", name + ".jpg")
filename = os.path.join("./known_faces/", f"{name}.jpg")
if os.path.exists(filename):
return tk.messagebox.showerror(
"Error", "A face with this name already exists."
)
# Show a pop-up message
resp = tk.messagebox.askokcancel(
if resp := tk.messagebox.askokcancel(
"Cheese", "Smile for the camera! Click OK to click and image."
)
if resp:
):
Comment on lines -168 to +173
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SaveFaceGUI.save_face refactored with the following changes:

This removes the following comments ( why? ):

# Show a pop-up message

ret, frame = self.cap.read()
if ret:
cv2.imwrite(filename, frame)
Expand Down
11 changes: 5 additions & 6 deletions detectors/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
faces_folder_path = "./known_faces/"
dlib_frontal_face_detector = dlib.get_frontal_face_detector()
shape_predictor = dlib.shape_predictor(
data_dir + "/shape_predictor_68_face_landmarks.dat"
f"{data_dir}/shape_predictor_68_face_landmarks.dat"
)
face_recognition_model = dlib.face_recognition_model_v1(
data_dir + "/dlib_face_recognition_resnet_model_v1.dat"
f"{data_dir}/dlib_face_recognition_resnet_model_v1.dat"
Comment on lines -13 to +16
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 13-16 refactored with the following changes:

)
face_detector = dlib.get_frontal_face_detector()

Expand All @@ -40,7 +40,7 @@ def find_match(known_faces, person_names, face):
if min_value < 0.58:
return person_names[min_index] + " ({0:.2f})".format(min_value)
if min_value < 0.65:
return person_names[min_index] + "?" + " ({0:.2f})".format(min_value)
return f"{person_names[min_index]}?" + " ({0:.2f})".format(min_value)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function find_match refactored with the following changes:

return "Not Found"


Expand Down Expand Up @@ -77,7 +77,7 @@ def load_face_encodings(faces_folder_path):

def recognize_faces_in_frame(frame):
faceClassifier = cv2.CascadeClassifier(
data_dir + "/haarcascade_frontalface_default.xml"
f"{data_dir}/haarcascade_frontalface_default.xml"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function recognize_faces_in_frame refactored with the following changes:

)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face_rects = faceClassifier.detectMultiScale(
Expand All @@ -89,8 +89,7 @@ def recognize_faces_in_frame(frame):
)
for x, y, w, h in face_rects:
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
face_encodings_in_image = get_face_encodings(frame)
if face_encodings_in_image:
if face_encodings_in_image := get_face_encodings(frame):
match = find_match(face_encodings, person_names, face_encodings_in_image[0])
cv2.putText(
frame,
Expand Down
3 changes: 1 addition & 2 deletions detectors/traffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@

async def image_processing(img):
model = load_model("./models/TSR.h5")
data = []
image = Image.fromarray(img)
image = image.resize((30, 30))
data.append(np.array(image))
data = [np.array(image)]
Comment on lines -55 to +57
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function image_processing refactored with the following changes:

X_test = np.array(data)
Y_pred = np.argmax(model.predict(X_test))
try:
Expand Down
4 changes: 1 addition & 3 deletions detectors/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def group_words_to_sentences(words):

# Convert the words to strings
sentences = [[w[4] for w in s] for s in sentences]
sentences = [" ".join(s) for s in sentences]

return sentences
return [" ".join(s) for s in sentences]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function group_words_to_sentences refactored with the following changes:



def wrap(func):
Expand Down