Ask Your Question

floris's profile - activity

2012-08-22 10:10:41 -0600 received badge  Editor (source)
2012-08-22 08:35:53 -0600 asked a question How to convert new cv::Mat to older CvSeq*

Hi All,

I upgraded from 2.1 to the newer 2.4.x version of OpenCV because I liked the idea of having the functionality to easily switch between different feature detectors and extractors. However, I discovered that this was not an easy task.

My biggest problem is that the new feature extractor stores the descriptors in a cv::Mat structure. However, my matching and fundamental matrix routines are using CvSeq*Descriptor as an input.

void MatchFeatures(CvMat *points1, CvMat *points2, CvSeq *kp1, CvSeq *desc1, CvSeq *kp2, CvSeq *desc2)

I spend hours on Google trying to find an answer.. but could not find anything.

I have got to convert from CvSeq* to cv::Mat... but do not know how to do this the other way around..

Here the code from CvSeq* to cv::Mat:

cv::Mat FromCvSeqToCvMat(CvSeq* Descriptors ) { int length = (int)(Descriptors->elem_size/sizeof(float)); cv::Mat m_object(Descriptors->total, length, CV_32F);

// copy descriptors
CvSeqReader obj_reader;
float* obj_ptr = m_object.ptr<float>(0);
cvStartReadSeq( Descriptors, &obj_reader );
for(int i = 0; i < Descriptors->total; i++ )
{
    const float* descriptor = (const float*)obj_reader.ptr;
    CV_NEXT_SEQ_ELEM( obj_reader.seq->elem_size, obj_reader );
    memcpy(obj_ptr, descriptor, length*sizeof(float));
    obj_ptr += length;
}
return m_object;

}

Anyone an idea how to do this in the opposite direction?

Greetings, Floris.