/************************************************************************ Copyright (C) 2015-2020. File name: Author: Greenapple QQ: 361348440 EMail: [email protected] Version: V1.0 Date: 2015/3/15 Description: STL vector usage Others: 无 Modification: 1.vector<vector<int>> 2.维数达到3维 1. 2015/3/15 : 第一次编写完成。 ************************************************************************/ #include <iostream> #include <vector> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> using namespace std; const int TOTAL_NUM=4; const int DIM=3; vector<vector<int>>vec_pt; void readData3Dims() { freopen("input_3.txt","r",stdin); for(int i=0;i<TOTAL_NUM;++i) { //int *temp=new int [DIM]; //int temp[DIM]; vector<int> vec_temp; for(int j=0;j<DIM;++j) { int tmp; cin>>tmp; vec_temp.push_back(tmp); //cout<<vec_temp[j]<<" "; } //cout<<endl; vec_pt.push_back(vec_temp); } fclose(stdin); } int main() { readData3Dims(); int vec_size=static_cast<int>(vec_pt.size()); cv::Mat_<float> vec(vec_size,DIM); vec.setTo(0); for(int y=0;y<vec.rows;++y) { for(int x=0;x<vec.cols;++x) { vector<int> vec_tmp; vec_tmp=vec_pt[y]; vec(y,x)=vec_tmp[x]; } } //show vec; for(int y=0;y<vec.rows;++y) { for(int x=0;x<vec.cols;++x) { cout<<vec(y,x)<<" "; } cout<<endl; } return 0; }
时间: 2024-12-10 10:58:32