Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Find contours speedup#26834

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
asmorkalov merged 19 commits intoopencv:4.xfromchacha21:findContours_speedup
Mar 12, 2025
Merged
Changes from1 commit
Commits
Show all changes
19 commits
Select commitHold shift + click to select a range
085e8e3
gather preliminary work into one commit
chacha21Jan 22, 2025
9278de7
better C++ grammar for gcc/clang
chacha21Jan 23, 2025
4dd8408
Do not use map for contour indexing
mshabuninJan 25, 2025
4a341bc
use vector instead of stack
chacha21Jan 25, 2025
c3347a4
changed an assert
chacha21Jan 25, 2025
a75ad49
try to minimize allocations
chacha21Jan 26, 2025
e8bcc40
fixed typo not detected by MSVC
chacha21Jan 26, 2025
b89bb69
new storage structure for the levels of TreeIterator
chacha21Jan 26, 2025
73bba4d
fixed move
chacha21Jan 26, 2025
1ca692a
Merge branch '4.x' into findContours_speedup
chacha21Jan 26, 2025
3dbd4ee
cleanup and optimizations
chacha21Jan 27, 2025
c0b747a
typo not detected at compile time
chacha21Jan 27, 2025
b9e2403
use abstraction for Contour::codes
chacha21Jan 27, 2025
1875ef6
use BlockStorage for codes
chacha21Jan 27, 2025
ce01235
remove unused debugging code
chacha21Jan 27, 2025
9938b26
Merge remote-tracking branch 'upstream/master' into findContours_speedup
chacha21Feb 20, 2025
45e2d17
changes as suggested by reviewer
chacha21Feb 20, 2025
e6f4e8a
typo
chacha21Feb 20, 2025
fd90ee4
indentation
chacha21Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
new storage structure for the levels of TreeIterator
The values stored in the `levels` member of TreeIterator seems to be mostly contiguous indices. Instead of allocating each index, we can just use ranges. It saves a lot of allocations.Still no visible performance improvement on test case.
  • Loading branch information
@chacha21
chacha21 committedJan 26, 2025
commitb89bb6970a2f9972bc66a4a0de74809f839d73ad
48 changes: 46 additions & 2 deletionsmodules/imgproc/src/contours_common.hpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -375,6 +375,50 @@ class vectorWithArena
size_t _size;
};

template<typename T>
class vectorRanges
{
public:
vectorRanges(void) = default;
vectorRanges(const vectorRanges&) = default;
vectorRanges(vectorRanges&& other) noexcept = default;
~vectorRanges() = default;
public:
vectorRanges& operator=(const vectorRanges&) = default;
vectorRanges& operator=(vectorRanges&& other) noexcept = default;
public:
bool empty(void) const {return !_size;}
size_t size(void) const {return _size;}
T at(size_t index) const {
for(const auto& range : _ranges) {
if (index < range.second)
return static_cast<T>(range.first+index);
else
index -= range.second;
}
return _ranges[0].first;//should not occur
}
T back(void) const {return at(_size-1);}
public:
void push_back(const T& value) {
if (_ranges.empty() || (value != back()+1))
_ranges.push_back(std::make_pair(value, 1));
else
++_ranges.back().second;
++_size;
}
void pop_back(void) {
if (_ranges.back().second == 1)
_ranges.pop_back();
else
--_ranges.back().second;
--_size;
}
private:
std::vector<std::pair<T, size_t> > _ranges;
size_t _size = 0;
};

template <typename T>
class TreeNode
{
Expand DownExpand Up@@ -500,7 +544,7 @@ template <typename T>
class TreeIterator
{
public:
TreeIterator(Tree<T>& tree_) : tree(tree_),levels(&tree._treeIteratorArena)
TreeIterator(Tree<T>& tree_) : tree(tree_)//,levels(&tree._treeIteratorArena)
{
CV_Assert(!tree.isEmpty());
levels.push_back(0);
Expand All@@ -525,7 +569,7 @@ class TreeIterator

private:
Tree<T>& tree;
vectorWithArena<int> levels;
vectorRanges<int> levels;
};

//==============================================================================
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp