Use std::priority_queue in inpaint function for performance improvement#25122
Use std::priority_queue in inpaint function for performance improvement#25122asmorkalov merged 4 commits intoopencv:4.xfrom
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.
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.
I see. That is a good idea. I'll fix it.
There was a problem hiding this comment.
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: |
|
|
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.