// This file is part of OpenCV project. // It is subject to the license terms in the LICENSE file found in the top-level directory // of this distribution and at http://opencv.org/license.html #define LOG_TAG "org.opencv.utils.Converters" #include "common.h" using namespace cv; // vector_int void Mat_to_vector_int(Mat& mat, std::vector& v_int) { v_int.clear(); CHECK_MAT(mat.type()==CV_32SC1 && mat.cols==1); v_int = (std::vector) mat; } void vector_int_to_Mat(std::vector& v_int, Mat& mat) { mat = Mat(v_int, true); } //vector_double void Mat_to_vector_double(Mat& mat, std::vector& v_double) { v_double.clear(); CHECK_MAT(mat.type()==CV_64FC1 && mat.cols==1); v_double = (std::vector) mat; } void vector_double_to_Mat(std::vector& v_double, Mat& mat) { mat = Mat(v_double, true); } // vector_float void Mat_to_vector_float(Mat& mat, std::vector& v_float) { v_float.clear(); CHECK_MAT(mat.type()==CV_32FC1 && mat.cols==1); v_float = (std::vector) mat; } void vector_float_to_Mat(std::vector& v_float, Mat& mat) { mat = Mat(v_float, true); } //vector_uchar void Mat_to_vector_uchar(Mat& mat, std::vector& v_uchar) { v_uchar.clear(); CHECK_MAT(mat.type()==CV_8UC1 && mat.cols==1); v_uchar = (std::vector) mat; } void vector_uchar_to_Mat(std::vector& v_uchar, Mat& mat) { mat = Mat(v_uchar, true); } void Mat_to_vector_char(Mat& mat, std::vector& v_char) { v_char.clear(); CHECK_MAT(mat.type()==CV_8SC1 && mat.cols==1); v_char = (std::vector) mat; } void vector_char_to_Mat(std::vector& v_char, Mat& mat) { mat = Mat(v_char, true); } //vector_Rect void Mat_to_vector_Rect(Mat& mat, std::vector& v_rect) { v_rect.clear(); CHECK_MAT(mat.type()==CV_32SC4 && mat.cols==1); v_rect = (std::vector) mat; } void vector_Rect_to_Mat(std::vector& v_rect, Mat& mat) { mat = Mat(v_rect, true); } //vector_Rect2d void Mat_to_vector_Rect2d(Mat& mat, std::vector& v_rect) { v_rect.clear(); CHECK_MAT(mat.type()==CV_64FC4 && mat.cols==1); v_rect = (std::vector) mat; } void vector_Rect2d_to_Mat(std::vector& v_rect, Mat& mat) { mat = Mat(v_rect, true); } //vector_RotatedRect void Mat_to_vector_RotatedRect(Mat& mat, std::vector& v_rect) { v_rect.clear(); CHECK_MAT(mat.type()==CV_32FC(5) && mat.cols==1); v_rect = (std::vector) mat; } void vector_RotatedRect_to_Mat(std::vector& v_rect, Mat& mat) { mat = Mat(v_rect, true); } //vector_Point void Mat_to_vector_Point(Mat& mat, std::vector& v_point) { v_point.clear(); CHECK_MAT(mat.type()==CV_32SC2 && mat.cols==1); v_point = (std::vector) mat; } //vector_Point2f void Mat_to_vector_Point2f(Mat& mat, std::vector& v_point) { v_point.clear(); CHECK_MAT(mat.type()==CV_32FC2 && mat.cols==1); v_point = (std::vector) mat; } //vector_Point2d void Mat_to_vector_Point2d(Mat& mat, std::vector& v_point) { v_point.clear(); CHECK_MAT(mat.type()==CV_64FC2 && mat.cols==1); v_point = (std::vector) mat; } //vector_Point3i void Mat_to_vector_Point3i(Mat& mat, std::vector& v_point) { v_point.clear(); CHECK_MAT(mat.type()==CV_32SC3 && mat.cols==1); v_point = (std::vector) mat; } //vector_Point3f void Mat_to_vector_Point3f(Mat& mat, std::vector& v_point) { v_point.clear(); CHECK_MAT(mat.type()==CV_32FC3 && mat.cols==1); v_point = (std::vector) mat; } //vector_Point3d void Mat_to_vector_Point3d(Mat& mat, std::vector& v_point) { v_point.clear(); CHECK_MAT(mat.type()==CV_64FC3 && mat.cols==1); v_point = (std::vector) mat; } void vector_Point_to_Mat(std::vector& v_point, Mat& mat) { mat = Mat(v_point, true); } void vector_Point2f_to_Mat(std::vector& v_point, Mat& mat) { mat = Mat(v_point, true); } void vector_Point2d_to_Mat(std::vector& v_point, Mat& mat) { mat = Mat(v_point, true); } void vector_Point3i_to_Mat(std::vector& v_point, Mat& mat) { mat = Mat(v_point, true); } void vector_Point3f_to_Mat(std::vector& v_point, Mat& mat) { mat = Mat(v_point, true); } void vector_Point3d_to_Mat(std::vector& v_point, Mat& mat) { mat = Mat(v_point, true); } //vector_Mat void Mat_to_vector_Mat(cv::Mat& mat, std::vector& v_mat) { v_mat.clear(); if(mat.type() == CV_32SC2 && mat.cols == 1) { v_mat.reserve(mat.rows); for(int i=0; i a = mat.at< Vec >(i, 0); long long addr = (((long long)a[0])<<32) | (a[1]&0xffffffff); Mat& m = *( (Mat*) addr ); v_mat.push_back(m); } } else { LOGD("Mat_to_vector_Mat() FAILED: mat.type() == CV_32SC2 && mat.cols == 1"); } } void vector_Mat_to_Mat(std::vector& v_mat, cv::Mat& mat) { int count = (int)v_mat.size(); mat.create(count, 1, CV_32SC2); for(int i=0; i >(i, 0) = Vec(addr>>32, addr&0xffffffff); } } void Mat_to_vector_vector_Point(Mat& mat, std::vector< std::vector< Point > >& vv_pt) { std::vector vm; vm.reserve( mat.rows ); Mat_to_vector_Mat(mat, vm); for(size_t i=0; i vpt; Mat_to_vector_Point(vm[i], vpt); vv_pt.push_back(vpt); } } void Mat_to_vector_vector_Point2f(Mat& mat, std::vector< std::vector< Point2f > >& vv_pt) { std::vector vm; vm.reserve( mat.rows ); Mat_to_vector_Mat(mat, vm); for(size_t i=0; i vpt; Mat_to_vector_Point2f(vm[i], vpt); vv_pt.push_back(vpt); } } void Mat_to_vector_vector_Point3f(Mat& mat, std::vector< std::vector< Point3f > >& vv_pt) { std::vector vm; vm.reserve( mat.rows ); Mat_to_vector_Mat(mat, vm); for(size_t i=0; i vpt; Mat_to_vector_Point3f(vm[i], vpt); vv_pt.push_back(vpt); } } void Mat_to_vector_vector_char(Mat& mat, std::vector< std::vector< char > >& vv_ch) { std::vector vm; vm.reserve( mat.rows ); Mat_to_vector_Mat(mat, vm); for(size_t i=0; i vch; Mat_to_vector_char(vm[i], vch); vv_ch.push_back(vch); } } void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, Mat& mat) { std::vector vm; vm.reserve( vv_ch.size() ); for(size_t i=0; i >& vv_pt, Mat& mat) { std::vector vm; vm.reserve( vv_pt.size() ); for(size_t i=0; i >& vv_pt, Mat& mat) { std::vector vm; vm.reserve( vv_pt.size() ); for(size_t i=0; i >& vv_pt, Mat& mat) { std::vector vm; vm.reserve( vv_pt.size() ); for(size_t i=0; i& v_vec, Mat& mat) { mat = Mat(v_vec, true); } void vector_Vec4f_to_Mat(std::vector& v_vec, Mat& mat) { mat = Mat(v_vec, true); } void vector_Vec6f_to_Mat(std::vector& v_vec, Mat& mat) { mat = Mat(v_vec, true); }