Speed up and reduce memory consumption for findContours#26690
Merged
asmorkalov merged 1 commit intoopencv:4.xfrom Dec 31, 2024
Merged
Conversation
asmorkalov
approved these changes
Dec 31, 2024
|
Thank you for your work, but I tested and found that the speed of this function in version 4.11 is slower than in version 4.7. #include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("111.bmp", cv::IMREAD_GRAYSCALE);
cv::Mat mask;
inRange(img, 110, 120, mask);
std::vector<std::vector<cv::Point>> v_cont;
for (int i = 0; i < 10; i++)
{
v_cont.clear();
auto start = chrono::system_clock::now();
cv::findContours(mask, v_cont, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
auto end = chrono::system_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(end - start) / 1000.;
cout << "4.11 findContours cost" << double(duration.count()) << "ms" << endl;
}
} |
Merged
Contributor
This is because this function has been rewritten from C to C++ between these releases, it needs additional refactoring of internal structures in order to return to previous speed. |
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.



Pull Request Readiness Checklist
Related to #26683
I ran reproducer from issue with one iteration.
Before
After
Speedup more than
2times and memory consumption reduction more than10timesSee 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.