首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Image.ptr<double>(0);在OpenCV中使用彩色图像

问使用Image.ptr<double>(0);在OpenCV中使用彩色图像
EN

Stack Overflow用户
提问于 2015-11-20 14:08:40
回答 1查看 777关注 0票数 0

我正在学习GrabCut in OpenCV (c++),我坚持这句话

代码语言:javascript
复制
coefs = model.ptr<double>(0);
mean = coefs + componentsCount;
cov = mean + 3*componentsCount;

哪里

模型为矩阵

厨师,平均,和cov是双倍*

componentsCount是一个常量整数

我想知道什么是厨师?是RGB值还是其他什么的?(以下代码的结果)

代码语言:javascript
复制
model.ptr<double>(0);

会发生什么事

代码语言:javascript
复制
cov = mean + 3*componentsCount;

谢谢你的答覆:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-11-20 17:39:35

Mat model不是彩色图像,而是高斯混合模型的模型。

全球监测团有以下几个私人备忘录:

代码语言:javascript
复制
Mat model;     
double* coefs; 
double* mean;  
double* cov;

model单通道双矩阵(CV64FC1),其一行数和列数等于modelSize*componentsCount,其中

代码语言:javascript
复制
componentsCount = 5 // line 60
modelSize = 13 // 3/*mean*/ + 9/*covariance*/ + 1/*component weight*/    // line 89

此数据存储在具有此布局的矩阵model中:

代码语言:javascript
复制
cw0, cw1, cw4, m00, m01, m02, m10, ..., m42, c00, c11, ...
^              ^                             ^
coefs = model.ptr<double>(0)                 ^
                                             mean + 3*componentsCount
               ^                             
               ^                            
               coefs + componentsCount

其中:

代码语言:javascript
复制
cw<i>    is the weight of the i-th component 
m<i><j>  is the j-th dimension mean of the i-th component
c<i><j>  is the j-th dimension covariance of the i-th component 

所以:

代码语言:javascript
复制
coefs = model.ptr<double>(0);   // points at the start of the weights into model
mean = coefs + componentsCount; // points at the start of the means into model
cov = mean + 3*componentsCount; // points at the start of the covariances into model

ptr<double>()只是在第0行的开头返回一个double*,即数据进入矩阵的开始。它相当于(double*)model.data。

基本上,coefs、mean和cov只是将适当的数据输入model的捷径。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33828741

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档