The code for keeping track of all contours is unnecessarily complex. It can be simplified a lot by simple allocating the vector of blocks up front and indexing it directly instead of doing everything relative to the 'last_block_idx' pointer and hiding the reusing of blocks.
The code for keeping track of all contours is unnecessarily complex. It can be simplified a lot by simple allocating the vector of blocks up front and indexing it directly instead of doing everything relative to the 'last_block_idx' pointer and hiding the reusing of blocks.