c++ - How to store point co-ordinates in vector data type in opencv? -


i have mat object (cv_8uc1) binary map 1's on positions , zeros otherwise.i want create vector stores co-ordinates of points mat 1.any suggestions on how go it. know can loop around image , check points following code

for( int p = 1; p <= img.rows; p++ )     { for( int q = 1; q <= img.cols; q++ )         {             if(  img.at<uchar>(p,q) == 1 )             {                 //what here ?              }         }     } 

also, need co-ordinates single precision floating point numbers.this use input function requires vectors. please gimme hint.i not familiar vector data types , stl.

if want find non-zero coordinates in binary map opencv, th ebest use findnonzero.

here example of how use (with dummy matrix idea):

cv::mat img(100, 100, cv_8u, cv::scalar(0)); img.at<uchar>(50, 50) = 255; img.at<uchar>(70, 50) = 255; img.at<uchar>(58, 30) = 255;  cv::mat nonzeroes;  cv::findnonzero(img, nonzeroes);  std::vector<cv::point2f> coords(nonzeroes.total());  (int = 0; < nonzeroes.total(); i++) {     coords[i] = nonzeroes.at<cv::point>(i); } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -