fixed /modules/text/textdetection.py sample #3092
Merged
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.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.
The sample python code
opencv/opencv_contrib/modules/text/sample/textdetection.py
contained errors and could not be be run. Moreover, the code was not optimized. This pull request fixes both issues.What caused errors:
In line (old) 27, cv.text.computeNMChannels(img) returns a tuple containing extracted image channels. There is an attempt to append negative channels which results in error as tuples are not mutable.
Fix
converted the returned tuple to list
Removed extra bracket pair in line 30 which could also be causing errors.
Also changed the loading path to
trained_classifierNM1.xml
for classifiers because my system was not able to detect the older pathPerformance Optimization
Issue:
From line 38 to 43 in the old code, the classifiers are loaded inside a for loop repeatedly. They need to be loaded only once to provide same results.
Fix:
Moved the classifiers loading outside the for block (line 33-39 in PR)
I have tested that the python file is now working