i want to Convert Mat to vector and Vector to mat in opencv .
my code :
void mat_to_vector(Mat in,vector<float> &out){
for (int i=0; i < in.rows; i++) {
for (int j =0; j < in.cols; j++){
//unsigned char temp;
//file << Dst.at<float>(i,j) << endl;
out.push_back(in.at<float>(i,j));
}
}
}
void vector_to_mat(vector<float> in, Mat out,int cols , int rows){
for (int i=rows-1; i >=0; i--) {
for (int j =cols -1; j >=0; j--){
out.at<float>(i,j) = in.back();
in.pop_back();
//file << Dst.at<float>(i,j) << endl;
// dst_temp.push_back(Dst.at<float>(i,j));
}
}
}
Above codes are slow.
are there faster solutions?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…