c++ - OpenCV fast mat element and neighbour access -


i use opencv (c++) mat matrix , want acces single mat elements fast possible. opencv tutorial, found code efficient acces:

for( = 0; < nrows; ++i)     {         p = i.ptr<uchar>(i);         ( j = 0; j < ncols; ++j)         {             p[j] = table[p[j]];         }     } 

for problem, need access mat element , neighbours (i-1,j-1) calculation. how can adapt given code acces single mat element , surrounding elements? since speed matters, want avoid mat.at<>(). efficient way acces mat value , neighbour values?

the pixel , neighbor pixels can formed cv::rect, can use:

cv::mat mat = ...; cv::rect roi= ...; // define based on neighbors defination cv::mat sub_mat = mat(roi); 

in case neighbors definition not regular, i.e. cannot form rectangle area, use mask instead. check out here examples.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -