Needing help to understand code

Hi,

New to the forum. Would need some help in understanding this line of code which the compiler simply refuse to compile

::cvflann::Matrix<T> m_queries((T*)queries.ptr<T>(0), queries.rows, queries.cols);

- the code is taken from OpenCV 2.2 about nearest neighbour algorithm, flann.hpp. Need some help in understanding this line about usage of template and casting.

Below is my interpretation:

-the first <T> set the m_quries template type ie setting return type of function m_queries.
- the second T (T*) cast the queries.ptr as pointer type T
- the third <T> seem to suggest to define the class variable ptr as type T

Is that right? The compiler seem to have difficulty understanding the last <T>... I am using gcc 3.3.2

Thanks for your help!

ptr is a (very much) overloaded member function of class Mat (queries is a variable of class Mat).
Some of these overloads are templated functions.
template<typename _Tp> _Tp* ptr(int i0, int i1, int i2);

The line itself ::cvflann::Matrix<T> m_queries((T*)queries.ptr<T>(0), queries.rows, queries.cols); looks acceptable.

I wonder if it is because of the age of your compiler.

I know that at one time if you declared/define a template function member in a class that was not a template
class (class Mat is not a template class) then you needed to use the template keyword when
using that member function.

::cvflann::Matrix<T> m_queries((T*)queries. template ptr<T>(0), queries.rows, queries.cols);

What is the actual error message you are getting??
Last edited on
Hi,

The compiler gives me an error

error:: syntax error before '>' token
error:: declaration of 'query' shadows a parameter
error:: syntax error before '.' token


I suppose you could be right that the compiler is just too old. Change the code wording by adding in the template keyword, the compiler runs smoothly.

However, in the non-debug mode, subsequent line in the code runs amok...

'return nnIndex -> radiusSearch(m_query, m_indices, m_dists,radiussearchParams);'

guess this might be my toolflag problem...

thanks for reading through the problem
Hi,

Need another query help...

Has admended accordingly as suggested in the library files(as below)

template <typename T>
Index_<T>::Index_(const Mat& dataset, const IndexParams& params)
{
CV_Assert(dataset.type() == CvType<T>::type());
CV_Assert(dataset.isContinuous());
::cvflann::Matrix<float> m_dataset((T*)dataset.template ptr<T>(0), dataset.rows, dataset.cols);

nnIndex = new ::cvflann::Index<T>(m_dataset, params);
nnIndex->buildIndex();
}


So how can I call this function? This function belongs to the namespace cvflann

So I am using the following codes

cv::Mat obj_mat = cvMat(3,3,CV_32F);
cvflann::KDTreeIndexParams S_params = cvflann::KDTreeIndexParams(2));
cvflann::Index flann_index( obj_mat, S_params);



Was given an invalid use of class template error. At first, I supposed the problem requires the class template usage be explicitly declared. So I have used

cvflann::Index<float> flann_index( obj_mat, S_params);

The compiler still gives similar problem... Should i also explicitly set <float> for the obj_mat? How to do it?

Thanks in advance
Topic archived. No new replies allowed.