【问题标题】:Mat access element OpenCV2.3垫访问元素OpenCV2.3
【发布时间】:2012-03-28 16:55:30
【问题描述】:

我已经阅读了一些关于 Mat 元素访问的帖子,并进行了一些试验,但都失败了。有人可以给我一个提示吗?

Mat vect(1,3, CV_32FC1);     
typedef Vec<float,1> Vec1f;  //**
// access ele. at (1,1)
vect.at<Vec1f>( Point(1,1 )) = 5;  // I used 1 channel so I defined a new element type as a workaround

我改编了这篇文章中的代码 opencv multi channel element access

而且,我认为 //** 行可以声明为:

typedef Vec<float> Vec1f;

根据 core.hpp 中的第 582 行: Vec(_Tp v0); //!

但是,它也不起作用

我对二维矩阵应用了同样的方法然后没问题:

Mat warp_mat(2,3, CV_32FC1);
typedef Vec<float,1> Vec1f;

warp_mat.at<Vec1f>( Point(0,0 )) = 1;
warp_mat.at<Vec1f>( Point(1,0 )) = 2;
warp_mat.at<Vec1f>( Point(2,0 )) = 5;
warp_mat.at<Vec1f>( Point(0,1 )) = 4;
warp_mat.at<Vec1f>( Point(1,1 )) = 5;
warp_mat.at<Vec1f>( Point(2,1 )) = 0;

一切正常!

【问题讨论】:

    标签: opencv matrix


    【解决方案1】:

    http://aishack.in/tutorials/opencvs-c-interface/

    Mat a=Mat(4,3, CV_32FC1);

    float elem_a= a.at(i,j); //访问元素aij,i从0到 rows-1 和 j 从 0 到 cols-1

    【讨论】:

    • 实际上,我已经尝试过 'at' 功能,但它不能以这种方式工作。有效的是:frame.at(30,10)。类型,这里是uchar,必须放在前面。
    • 我遇到的另一个问题是:该矩阵是具有 3 个通道的真实图像 matrix.at(i,j) 可以访问元素 i,j 但哪个通道?如何访问我想要的每个频道??
    • "如果你在处理多通道 Mat,事情会稍微复杂一些。但仍然比 CV_MAT_ELEM 或 CV_IMAGE_ELEM 宏更容易。你必须使用 ptr 方法来获取指向特定行。然后使用 [] 访问特定通道中的特定像素:" type elem = matrix.ptr(i)[Nc*j+c]
    • 我目前的选择是使用 Mat 矩阵的“at”。它工作得很好
    猜你喜欢
    • 1970-01-01
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多