convert openCV matrix into vector -


looks deceptively easy. after know std or opencv vector can converted matrix this:

vector<point> iptvec(10); mat ip(iptvec); 

the reverse suggested in opencv cheatsheet:

vector<point2f> ptvec = mat_ <point2f>(ip); 

however, there 1 caveat: matrix has have 1 row or 1 column. convert arbitrary matrix have reshape:

int sz = ip.cols*ip.rows; vector<point2f> ptvec = mat <point2f>(ip.reshape(1, sz)); 

otherwise error:

*opencv error: assertion failed (dims == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0)) in create, file /home/.../opencv-2.4.2/modules/core/src/matrix.cpp, line 1385...

create 2dim vector , fill each row. e.g:

mat ip=mat::zeros(10, 20, cv_8uc1); vector<vector<int>> ptvec; (int = 0; < ip.rows; i++) {     vector<int> row;         ip.row(i).copyto(row);     ptvec.push_back(row); } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -