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.
精彩评论