Seb
Seb

Reputation: 3564

converting a vector of keypoints to a CvSeq

I had a quick OpenCV question. Is it possible to take a vector of keypoints and convert it to a CvSeq?

Thanks in advance.

Upvotes: 4

Views: 2827

Answers (1)

jmartel
jmartel

Reputation: 2781

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,

Upvotes: 2

Related Questions