Using iterator with sparseMat value [closed]

asked 2016-11-25 10:45:12 -0600

Ralph058 gravatar image

updated 2016-11-25 11:17:35 -0600

berak gravatar image

I am trying to access elements in a sparseMat using value and the iterator.. The elements are of the type Vec5f, which has been declared.

typedef Vec<float, 5> Vec5f;

The iterator is declared with

 cv::SparseMatConstIterator_<float> it = sparseLoc.begin<float>();
 cv::SparseMatConstIterator_<float> it_end = sparseLoc.end<float>();

The IDE (Eclipse) doesn't allow using type <vec5f> for this.

The loop is

for(; it != it_end; ++it)
     {
         float Iter = *it;
         const SparseMat::Node* itNode = it.node();
         Spot = it.value<Vec5f>();
         Intens = Spot[I];
         Vert = Spot[V];
         Horiz = Spot[H];
         DeltaH = Spot[DH];
         DeltaI = Spot[DI];
         itTestFile << Iter << ", " <<  Intens << ", " <<  Vert  << ", " << Horiz<< ", "
                         <<  DeltaH  << ", " << DeltaI << endl;
     }

(If you are trying to figure out its purpose, I am trying to see how the iterator and the x,y access compare.) I get the exception

OpenCV Error: Assertion failed (_m->type() == DataType<_Tp>::type) in SparseMatConstIterator_, file /usr/local/include/opencv2/core/mat.inl.hpp, line 2888
terminate called after throwing an instance of 'cv::Exception'
  what():  /usr/local/include/opencv2/core/mat.inl.hpp:2888: error: (-215) _m->type() == DataType<_Tp>::type in function SparseMatConstIterator

It doesn't show the calling line number. i tried changing the Vec5f in the it.value statement and I get the same exception. So, I assume it is thrown by the SparseMatConstInterator_ declaration.

Any hints on how to fix this?

Thanks Ralph

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-26 15:41:37.847015

Comments

The IDE (Eclipse) doesn't allow using type <vec5f> for this.

your ide is irrelevant, what matters is your compiler.

( and Vec5f is the correct type, while float is wrong )

berak gravatar imageberak ( 2016-11-25 11:11:46 -0600 )edit

please also show, how you setup your sparseLoc Mat

berak gravatar imageberak ( 2016-11-25 11:22:50 -0600 )edit

It looks like I answered rather than commented. Hence, it may not show up for a few days.

The first hint solved the problem. It appears that the sparseMat is populated in random order, so I can't use the iterator..

Ralph058 gravatar imageRalph058 ( 2016-11-25 11:52:50 -0600 )edit