-
Notifications
You must be signed in to change notification settings - Fork 58
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
Apply fixes from -Wclippy::pedantic
#13
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 |
---|---|---|
|
@@ -95,10 +95,11 @@ impl OcrEngine { | |
/// Returns an unordered list of the oriented bounding rectangles of each | ||
/// word found. | ||
pub fn detect_words(&self, input: &OcrInput) -> Result<Vec<RotatedRect>, Box<dyn Error>> { | ||
let Some(detector) = self.detector.as_ref() else { | ||
return Err("Detection model not loaded".into()); | ||
}; | ||
detector.detect_words(input.image.view(), self.debug) | ||
if let Some(detector) = self.detector.as_ref() { | ||
detector.detect_words(input.image.view(), self.debug) | ||
} else { | ||
Err("Detection model not loaded".into()) | ||
} | ||
} | ||
|
||
/// Perform layout analysis to group words into lines and sort them in | ||
|
@@ -128,17 +129,18 @@ impl OcrEngine { | |
input: &OcrInput, | ||
lines: &[Vec<RotatedRect>], | ||
) -> Result<Vec<Option<TextLine>>, Box<dyn Error>> { | ||
let Some(recognizer) = self.recognizer.as_ref() else { | ||
return Err("Recognition model not loaded".into()); | ||
}; | ||
recognizer.recognize_text_lines( | ||
input.image.view(), | ||
lines, | ||
RecognitionOpt { | ||
debug: self.debug, | ||
decode_method: self.decode_method, | ||
}, | ||
) | ||
if let Some(recognizer) = self.recognizer.as_ref() { | ||
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. This is OK, although if new lines were added to the happy path, I'd probably want to revert back to the early-exit. 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. if I understand correctly, the two versions of the code operate identically and the Usually let else is used when there are a lot of following code, where the If i inadvertently introduced any change in behavior I think this should also revert back to the original. 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.
Yes, this is one reason. The other is to logically have early-exit checks at the top of the function and then have the main body concentrate on the happy path. This also matters mainly when there are multiple early-exits. With the current body both are easy to read, and I would be fine with either. |
||
recognizer.recognize_text_lines( | ||
input.image.view(), | ||
lines, | ||
RecognitionOpt { | ||
debug: self.debug, | ||
decode_method: self.decode_method, | ||
}, | ||
) | ||
} else { | ||
Err("Recognition model not loaded".into()) | ||
} | ||
} | ||
|
||
/// Convenience API that extracts all text from an image as a single string. | ||
|
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.
I slightly prefer
to_vec
here because it makes the type more obvious.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.
Looking into the code, obstacles is already made into a vec above
line 57
let mut obstacles = obstacles.to_vec();
Since is not consumed elsewhere later I think we can just use the shorthand initialization without
.clone()
orto_vec()
it would look like this
do you still prefer the original over this?
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.
You're right. The clone looks redundant. This could be made clearer by moving initialization of it inside the
!boundary.is_empty()
check.