#include "converters.h" #ifdef DEBUG #include #define MODULE_LOG_TAG "OpenCV.converters" #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__)) #else //DEBUG #define LOGD(...) #endif //DEBUG using namespace cv; #define CHECK_MAT(cond) if(cond){ LOGD(#cond); return; } // vector_int void Mat_to_vector_int(Mat& mat, vector& v_int) { v_int.clear(); CHECK_MAT(mat.type()!= CV_32SC1 || mat.rows!=1); v_int = (vector) mat; } void vector_int_to_Mat(vector& v_int, Mat& mat) { mat = Mat(v_int); } //vector_double void Mat_to_vector_double(Mat& mat, vector& v_double) { v_double.clear(); CHECK_MAT(mat.type()!= CV_64FC1 || mat.rows!=1); v_double = (vector) mat; } void vector_double_to_Mat(vector& v_double, Mat& mat) { mat = Mat(v_double); } // vector_float void Mat_to_vector_float(Mat& mat, vector& v_float) { v_float.clear(); CHECK_MAT(mat.type()!= CV_32FC1 || mat.rows!=1); v_float = (vector) mat; } void vector_float_to_Mat(vector& v_float, Mat& mat) { mat = Mat(v_float); } //vector_uchar void Mat_to_vector_uchar(Mat& mat, vector& v_uchar) { v_uchar.clear(); CHECK_MAT(mat.type()!= CV_8UC1 || mat.rows!=1); v_uchar = (vector) mat; } //vector_Rect void Mat_to_vector_Rect(Mat& mat, vector& v_rect) { v_rect.clear(); CHECK_MAT(mat.type()!= CV_32SC4 || mat.rows!=1); v_rect = (vector) mat; /*for(int i=0; i v=mat.at< Vec >(0, i); v_rect.push_back( Rect(v[0], v[1], v[2], v[3]) ); }*/ } void vector_Rect_to_Mat(vector& v_rect, Mat& mat) { mat = Mat(v_rect); /*mat.create(1, v_rect.size(), CV_32SC4); for(size_t i=0; i >(0, i) = Vec(v_rect[i].x, v_rect[i].y, v_rect[i].width, v_rect[i].height); }*/ } //vector_Point void Mat_to_vector_Point(Mat& mat, vector& v_point) { v_point.clear(); CHECK_MAT(mat.type()!= CV_32SC2 || mat.rows!=1); v_point = (vector) mat; /*for(int i=0; i >(0, i) ) );*/ } void vector_Point_to_Mat(vector& v_point, Mat& mat) { mat = Mat(v_point); /*mat.create(1, v_point.size(), CV_32SC2); for(size_t i=0; i >(0, i) = Vec(v_point[i].x, v_point[i].y);*/ } //vector_KeyPoint void Mat_to_vector_KeyPoint(Mat& mat, vector& v_kp) { v_kp.clear(); CHECK_MAT(mat.type()!= CV_64FC(7) || mat.rows!=1); for(int i=0; i v = mat.at< Vec >(0, i); KeyPoint kp((float)v[0], (float)v[1], (float)v[2], (float)v[3], (float)v[4], (int)v[5], (int)v[6]); v_kp.push_back(kp); } return; } void vector_KeyPoint_to_Mat(vector& v_kp, Mat& mat) { int count = v_kp.size(); mat.create(1, count, CV_64FC(7)); for(int i=0; i >(0, i) = Vec(kp.pt.x, kp.pt.y, kp.size, kp.angle, kp.response, kp.octave, kp.class_id); } } //vector_Mat void Mat_to_vector_Mat(cv::Mat& mat, std::vector& v_mat) { v_mat.clear(); if(mat.type() == CV_32SC2 && mat.rows == 1) { for(int i=0; i a = mat.at< Vec >(0, i); long long addr = (((long long)a[0])<<32) | a[1]; Mat& m = *( (Mat*) addr ); v_mat.push_back(m); } } } void vector_Mat_to_Mat(std::vector& v_mat, cv::Mat& mat) { int count = v_mat.size(); mat.create(1, count, CV_32SC2); for(int i=0; i >(0, i) = Vec(addr>>32, addr&0xffffffff); } }