Skip to content

fixed /modules/text/textdetection.py sample #3092

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

Merged
merged 1 commit into from
Oct 31, 2021

Conversation

aimbot6120
Copy link
Contributor

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • [ Y] I agree to contribute to the project under Apache 2 License.
  • [ Y] To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • [ Y] The PR is proposed to proper branch
  • [ N] There is reference to original bug report and related work
  • [ N] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • [ N] The feature is well documented and sample code can be built with the project CMake

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 path

pathname+'/trained_classifierNM1.xml'

Performance 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

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution 👍

@opencv-pushbot opencv-pushbot merged commit 9100b8a into opencv:master Oct 31, 2021
@aimbot6120 aimbot6120 deleted the sample_optimization branch October 31, 2021 20:07
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants