开发者

OpenCV: how to access one contour in O(1) after call cvFindContours()?

开发者 https://www.devze.com 2023-02-03 18:34 出处:网络
I\'m using OpenCV to compare two blobs in two images. Suppose I\'ve known a pair of blobs that are likely to be similar, and I know their indices

I'm using OpenCV to compare two blobs in two images. Suppose I've known a pair of blobs that are likely to be similar, and I know their indices in the contour arrays (generated by cvFindContours()), how can I get access to one contour in a constant time?

The most cumbersome way is to use the link operation (contours=contours->h_next) multiple times, but I wonder if there is a faster way to retr开发者_运维技巧ieve one contour in an array.

I use CV_RETR_EXTERNAL and CV_CHAIN_APPROX_NONE in calling cvFindContours().

Thanks! -J.C.


I think the function cvGetSeqElem does what you want. Quoting the OpenCV docs: "The function has O(1) time complexity assuming that the number of blocks is much smaller than the number of elements." I suppose "blocks" means "contours" in this context.

Also, take a look at cvCvtSeqToArray (link), which copies a sequence to one continuous block of memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号