相关疑难解决方法(0)

在OpenCV中将矢量转换为mat

我使用opencv 2.4.3使用以下代码执行向量到矩阵转换:

struct Component
{
    cv::Rect box;
    double area;
    double circularity; 
}

int main ( ... )
{
     cv::vector < Component > components;         
     cv::Mat componentMat ( components, true );
     std::cout << componentMat;
     return 0; 
}
Run Code Online (Sandbox Code Playgroud)

但它发出错误,说:

OpenCV Error: Unsupported format or combination of formats() in unknown function, file ...\opencv\modules\core\src\out.cpp, line 111
Run Code Online (Sandbox Code Playgroud)

我在这做错了什么?有没有其他方法将此向量转换为矩阵形式?谢谢.

c++ opencv vector matrix type-conversion

10
推荐指数
1
解决办法
2万
查看次数

将Mat转换为vector <float>,将<float>转换为opencv中的mat

我想在Opencv中将Mat转换为vector并将Vector转换为mat.

我的代码:

     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));
            }
        }
}
Run Code Online (Sandbox Code Playgroud)

以上代码很慢.有更快的解决方案吗?

c++ opencv

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×2

opencv ×2

matrix ×1

type-conversion ×1

vector ×1