[Fix] Update image decoding and processing in Worker class#193
Merged
GreatV merged 1 commit intoPFCCLab:mainfrom Jul 3, 2025
Merged
[Fix] Update image decoding and processing in Worker class#193GreatV merged 1 commit intoPFCCLab:mainfrom
GreatV merged 1 commit intoPFCCLab:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refines OCR image handling in libs/autoDialog.py for robustness and adjusts OCR orientation settings in PPOCRLabel.py.
- Disable textline orientation detection in OCR configuration to streamline orientation handling.
- Decode images into memory before extracting dimensions and passing them to OCR, improving error handling.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| libs/autoDialog.py | Decode image to img variable, extract shape, and pass img to OCR instead of file path |
| PPOCRLabel.py | Set use_textline_orientation to False in OCR parameters |
Comments suppressed due to low confidence (1)
libs/autoDialog.py:48
- [nitpick] Consider adding unit tests for both branches of this size check (images smaller and larger than 32×32) to verify correct handling of edge cases.
if h > 32 and w > 32:
| img = cv2.imdecode( | ||
| np.fromfile(img_path, dtype=np.uint8), cv2.IMREAD_COLOR | ||
| ).shape | ||
| ) |
There was a problem hiding this comment.
cv2.imdecode can return None when decoding fails; add a check for img is None before accessing img.shape to avoid runtime errors.
Suggested change
| ) | |
| ) | |
| if img is None: | |
| logger.warning("Failed to decode image: %s", img_path) | |
| self.result_dic = None | |
| continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request includes updates to improve the functionality and accuracy of OCR processing in the
PPOCRLabelandautoDialogmodules. The key changes involve modifying configuration parameters and fixing how images are handled during OCR prediction.Changes to OCR configuration:
PPOCRLabel.py, theget_strmethod now sets theuse_textline_orientationparameter toFalse, disabling textline orientation detection. This change likely reflects a shift in how text orientation is handled in the OCR pipeline.Fixes to image handling:
libs/autoDialog.py, therunmethod now ensures that images are properly decoded before shape extraction and OCR prediction. Thecv2.imdecodefunction's output is stored in a variable (img) before accessing its shape, and the decoded image itself is passed to the OCR prediction method instead of the file path. This improves the robustness of the image processing workflow.