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
Post a Comment