-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| detector = FaceDetector(cascade_path) | ||
| face_boxes = detector.detect(gray, 1.2, 5) | ||
| print("{} face(s) found".format(len(face_boxes))) | ||
| print(f"{len(face_boxes)} face(s) found") |
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.
Lines 15-15 refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| # Detect faces in the image | ||
| boxes = self.face_cascade.detectMultiScale(image, scale_factor, min_neighbors, flags=cv2.CASCADE_SCALE_IMAGE) | ||
|
|
||
| # Return the bounding boxes | ||
| return boxes | ||
| return self.face_cascade.detectMultiScale( | ||
| image, scale_factor, min_neighbors, flags=cv2.CASCADE_SCALE_IMAGE | ||
| ) |
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 FaceDetector.detect refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# Return the bounding boxes
# Detect faces in the image
| # Detect faces in the image | ||
| boxes = self.face_cascade.detectMultiScale(image, scale_factor, min_neighbors, flags=cv2.CASCADE_SCALE_IMAGE) | ||
|
|
||
| # Return the bounding boxes | ||
| return boxes | ||
| return self.face_cascade.detectMultiScale( | ||
| image, scale_factor, min_neighbors, flags=cv2.CASCADE_SCALE_IMAGE | ||
| ) |
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 FaceDetector.detect refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# Return the bounding boxes
# Detect faces in the image
|
|
||
| # Return the translated image | ||
| return shifted | ||
| return cv2.warpAffine(image, matrix, (image.shape[1], image.shape[0])) |
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 translate refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# Return the translated image
| rotated = cv2.warpAffine(image, matrix, (w, h)) | ||
|
|
||
| # Return the rotated image | ||
| return rotated | ||
| return cv2.warpAffine(image, matrix, (w, h)) |
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 rotate refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# Return the rotated image
| # Resize the image | ||
| resized = cv2.resize(image, dim, interpolation=inter) | ||
|
|
||
| # Return the resized image | ||
| return resized | ||
| return cv2.resize(image, dim, interpolation=inter) |
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 resize refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
This removes the following comments ( why? ):
# Return the resized image
# Resize the image
| image_paths = sorted(glob.glob(path_to_images + "/*.png")) | ||
| mask_paths = sorted(glob.glob(path_to_masks + "/*.png")) | ||
| image_paths = sorted(glob.glob(f"{path_to_images}/*.png")) | ||
| mask_paths = sorted(glob.glob(f"{path_to_masks}/*.png")) |
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.
Lines 16-72 refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation) - Replace call to format with f-string (
use-fstring-for-formatting)
| min_matches = 40 | ||
|
|
||
| # Initialize the database dictionary of covers | ||
| database = {} | ||
|
|
||
| # Loop over the database | ||
| for l in csv.reader(open(database_path)): | ||
| # Update the database using the image ID as the key | ||
| database[l[0]] = l[1:] | ||
|
|
||
| # If SIFT is to be used, then update the parameters | ||
| if use_sift: | ||
| min_matches = 50 | ||
| database = {l[0]: l[1:] for l in csv.reader(open(database_path))} | ||
|
|
||
| min_matches = 50 if use_sift else 40 | ||
| # Initialize the cover descriptor and cover matcher | ||
| cover_descriptor = CoverDescriptor(use_sift=use_sift) | ||
| cover_matcher = CoverMatcher(cover_descriptor, glob.glob(covers_path + "/*.png"), ratio=ratio, min_matches=min_matches, | ||
| use_hamming=use_hamming) | ||
| cover_matcher = CoverMatcher( | ||
| cover_descriptor, | ||
| glob.glob(f"{covers_path}/*.png"), | ||
| ratio=ratio, | ||
| min_matches=min_matches, | ||
| use_hamming=use_hamming, | ||
| ) |
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.
Lines 18-35 refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Convert for loop into dictionary comprehension (
dict-comprehension) - Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Move setting of default value for variable into
elsebranch (introduce-default-else) - Replace if statement with if expression (
assign-if-exp)
This removes the following comments ( why? ):
# If SIFT is to be used, then update the parameters
# Update the database using the image ID as the key
# Loop over the database
|
|
||
| # If matches were found, sort them | ||
| if len(results) > 0: | ||
| if results: |
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 CoverMatcher.search refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison)
| matches = [] | ||
|
|
||
| # Loop over the raw matches | ||
| for match in raw_matches: | ||
| # Ensure the distance is within a certain ratio of each other | ||
| if len(match) == 2 and match[0].distance < match[1].distance * self.ratio: | ||
| matches.append((match[0].trainIdx, match[0].queryIdx)) | ||
| matches = [ | ||
| (match[0].trainIdx, match[0].queryIdx) | ||
| for match in raw_matches | ||
| if len(match) == 2 and match[0].distance < match[1].distance * self.ratio | ||
| ] |
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 CoverMatcher.match refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
This removes the following comments ( why? ):
# Ensure the distance is within a certain ratio of each other
# Loop over the raw matches
Branch
masterrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
masterbranch, then run:Help us improve this pull request!