开发者

converting a vector of keypoints to a CvSeq

I had a quick OpenCV question. Is 开发者_JAVA技巧it possible to take a vector of keypoints and convert it to a CvSeq?

Thanks in advance.


I don't know why you could want that but it should be possible, with these functions you can do whatever you want :

I should add, that the following is a mix of C and C++ (in OpenCV as well)

CreateSeq CvSeq* cvCreateSeq(int seqFlags, int headerSize, int elemSize, CvMemStorage* storage)

SeqPush char* cvSeqPush(CvSeq* seq, void* element=NULL)

Here is the code, i have not tried it yet, please let me know if there are errors, if it works or not, i just gave it a try...

vector<KeyPoint> myKeypointVector; //Your KeyPoint vector
// Do whatever you want with your vector

CvMemStorage* storage = cvCreateMemStorage(0) 
// By default the flag 0 is 64K 
// but myKeypointVector.size()*(sizeof(KeyPoint)+sizeof(CvSeq)) should work
// it may be more efficient but be careful there may have seg fault 
// (not sure about the size

CvSeq* myKeypointSeq = cvCreateSeq(0,sizeof(CvSeq),sizeof(KeyPoint),storage);
// Create the seq at the location storage

for (size_t i=0; myKeypointVector.size(); i++) {
    int* added = (int*)cvSeqPush(myKeypointSeq,&(myKeypointVector[i]));
    // Should add the KeyPoint in the Seq
}

cvClearMemStorage( storage ); 
cvReleaseMemStorage(&storage); 

Julien,

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜