c++ - How can I reshape a Mat 2D to vector<vector<Mat>>? -


i convert mat dimensions [2000][256] , want convert vector<vector<mat> > dimensions [256][20][10][10]. in matlab, possible reshape(mat2d, 10, 10, 20, 256); same here.

i found 1 solution:

vector<vector<mat>>  reshape2d4d(mat &a, int dim1, int dim2, int dim3, int dim4) {     vector<vector<mat>> b;     (int = 0; i<dim1; i++) {         b.push_back(vector<mat>());         (int j = 0; j<dim2; j++)             b[i].push_back(mat(dim3, dim4, cv_64f, scalar::all(1)));     }     mat in = a.reshape(1, 1);     mat subimg;      (int = 0; < 256; i++)     {         (int j = 0; j < 20; j++)         {             subimg = in(cv::range(0, 1), cv::range(100*j, 100*j + 100));             subimg.reshape(10, 10);             b[i][j] = subimg;         }     }     return b; } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -