注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

G G I C C I

 
 
 

日志

 
 

OpenCV函数的参数用法(1 mask)  

2012-07-21 14:24:51|  分类: OpenCV |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

Title :

  • OpenCV
  • OpenCV 函数的参数用法之 mask

Fn :

包含 mask 参数的一些函数如下 [摘自opencv 2.3.1版本 C++]

  • void add(InputArray src1, InputArray src2, OutputArray dst, InputArray mask=noArray(), int dtype=-1)
  • subtract
  • bitwise_and, bitwise_not, bitwise_or, bitwise_xor
  • mean, menStdDev
  • minMaxLoc
  • norm, normalize
  • grabCut
  • calcHist

Quote :

mask Optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed. [From OpenCV2.3.1 Doc]

mask 是一个8位的单通道数组,它指定了目标数组哪些元素会被修改。以 add 函数为例,请见 Code


Code :

   1: /*
   2:     Author : Ggicci
   3:     Date   : 2012.07.20
   4:     Title  : How to use opencv's parameter - mask ?
   5: */
   6: int main()
   7: {    
   8:     Mat m(10, 10, CV_8U);
   9:     //RNG类对象rng, 以统一分布(Uniform Distribution)随机填充矩阵 m 和 n
  10:     cv::RNG rng;
  11:     rng.fill(m, RNG::UNIFORM, 0, 10);
  12:     cout << "m = " << endl << m << endl << endl;
  13: 
  14:     Mat n(10, 10, CV_8U);
  15:     rng.fill(n, RNG::UNIFORM, 8, 10);
  16:     cout << "n = " << endl << n << endl << endl;
  17:     
  18:     Mat dst;
  19:     //指定 mask
  20:     Mat mask(10, 10, CV_8U, Scalar(0));
  21:     Mat specified(mask, Rect(2, 5, 4, 4));
  22:     specified.setTo(1);
  23:     cout << "mask = " << endl << mask << endl << endl;
  24: 
  25:     cv::add(m, n, dst, mask);
  26:     cout << "dst = " << endl << dst << endl << endl;
  27: 
  28:     return 0;
  29: }
Output :
   1: m =
   2: [6, 7, 9, 9, 7, 0, 6, 3, 6, 9;
   3:   1, 8, 7, 8, 5, 3, 8, 1, 7, 3;
   4:   3, 3, 5, 4, 8, 2, 6, 1, 2, 2;
   5:   6, 1, 0, 7, 3, 5, 0, 6, 3, 3;
   6:   7, 5, 0, 5, 3, 0, 2, 7, 1, 7;
   7:   9, 8, 8, 3, 9, 5, 4, 1, 8, 3;
   8:   8, 1, 8, 7, 7, 0, 3, 8, 8, 3;
   9:   8, 9, 5, 1, 1, 3, 3, 3, 4, 7;
  10:   2, 7, 6, 8, 2, 4, 9, 5, 6, 1;
  11:   5, 0, 5, 7, 8, 4, 1, 0, 4, 8]
  12: 
  13: n =
  14: [9, 8, 9, 8, 8, 9, 9, 9, 9, 9;
  15:   9, 9, 9, 9, 9, 8, 8, 9, 9, 9;
  16:   8, 8, 9, 9, 8, 9, 9, 9, 8, 9;
  17:   9, 9, 8, 9, 9, 8, 8, 8, 8, 8;
  18:   8, 8, 9, 8, 9, 9, 8, 8, 8, 8;
  19:   9, 9, 9, 9, 8, 8, 8, 9, 9, 8;
  20:   9, 9, 8, 8, 8, 9, 9, 8, 8, 9;
  21:   9, 8, 9, 9, 8, 9, 8, 9, 9, 8;
  22:   9, 8, 9, 9, 9, 9, 8, 9, 8, 8;
  23:   8, 8, 9, 9, 9, 8, 9, 8, 9, 9]
  24: 
  25: mask =
  26: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  27:   0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  28:   0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  29:   0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  30:   0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
  31:   0, 0, 1, 1, 1, 1, 0, 0, 0, 0;
  32:   0, 0, 1, 1, 1, 1, 0, 0, 0, 0;
  33:   0, 0, 1, 1, 1, 1, 0, 0, 0, 0;
  34:   0, 0, 1, 1, 1, 1, 0, 0, 0, 0;
  35:   0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  36: 
  37: dst =
  38: [205, 205, 205, 205, 205, 205, 205, 205, 205, 205;
  39:   205, 205, 205, 205, 205, 205, 205, 205, 205, 205;
  40:   205, 205, 205, 205, 205, 205, 205, 205, 205, 205;
  41:   205, 205, 205, 205, 205, 205, 205, 205, 205, 205;
  42:   205, 205, 205, 205, 205, 205, 205, 205, 205, 205;
  43:   205, 205, 17, 12, 17, 13, 205, 205, 205, 205;
  44:   205, 205, 16, 15, 15, 9, 205, 205, 205, 205;
  45:   205, 205, 14, 10, 9, 12, 205, 205, 205, 205;
  46:   205, 205, 15, 17, 11, 13, 205, 205, 205, 205;
  47:   205, 205, 205, 205, 205, 205, 205, 205, 205, 205]
  48: 
  49: 请按任意键继续. . .//mask的红色部分指定了dst被修改的部分(同样以红色标出),其余部分为dst的初始化值

End :

Author : Ggicci

谢谢阅读,有误希望指正!

--OpenCV 初学者

此文描述了 mask 的基本用法,在学习过程中如果有其它的用法会继续更新本文。

  评论这张
 
阅读(3898)| 评论(0)
推荐

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017