-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| if prev_ss != ss: | ||
| self.text_label.delete(1.0, tk.END) | ||
| self.text_label.insert(tk.END, ss) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| ret, frame = self.cap.read() | ||
| if ret: | ||
| cv2.imwrite(filename, frame) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
| ) | ||
| face_detector = dlib.get_frontal_face_detector() | ||
|
|
||
|
|
@@ -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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return "Not Found" | ||
|
|
||
|
|
||
|
|
@@ -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" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| ) | ||
| gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | ||
| face_rects = faceClassifier.detectMultiScale( | ||
|
|
@@ -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, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| X_test = np.array(data) | ||
| Y_pred = np.argmax(model.predict(X_test)) | ||
| try: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def wrap(func): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
TextDetectorGUI.updaterefactored with the following changes:use-join)