-
-
Notifications
You must be signed in to change notification settings - Fork 56.4k
Use std::priority_queue in inpaint function for performance improvement #25122
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
Conversation
|
Perf results (11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz): |
|
@unnonouno Thanks a lot for the patch. Could you provide performance test case, where the improvement is visible. For now I see ~5% speedup. |
| CvPriorityQueueFloat& operator=(const CvPriorityQueueFloat &); // assign disabled | ||
|
|
||
| protected: | ||
| CvHeapElem *mem,*empty,*head,*tail; |
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 propose to remove CvPriorityQueueFloat as it is not public API and replace its usage with std object calls. cv::Ptr is not needed any more and you can use std::priority_queue& as parameter.
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 see. That is a good idea. I'll fix it.
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.
Actually I need to add next_order variable in the priority queue class to keep insertion order for complete compatibility. It is because std::priority_queue cannot keep insertion order when two elements have the same score.
So I think it is simpler to keep this class. If it is OK to break compatibility, i can remove this variable. Even in that case, the result is almost same. How do you think?
|
Thanks a lot. It depends on the size of the image. I'll make another performance test with a large image. |
|
Please use existing test images from opencv_extra + resize, if it's required. I do not think, that we need extra files for it. |
|
I made a dot pattern mask, and the PR is significantly faster.
This PR: |
|
asmorkalov
left a comment
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.
👍
|
Thank you for quick review! |
Use std::priority_queue in inpaint function for performance improvement opencv#25122 In `cv::inpaint` implementation, it uses a priority queue with O(n) time linear search. For large images it is very slow. I replaced it with C++'s standard library `std::priority_queue`, that uses O(log(n)) algorithm. In my use case, it is x10 faster than the original. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
In
cv::inpaintimplementation, it uses a priority queue with O(n) time linear search. For large images it is very slow.I replaced it with C++'s standard library
std::priority_queue, that uses O(log(n)) algorithm.In my use case, it is x10 faster than the original.
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.