OpenCV Mat::ones()用法及注意事项

今天在用函数ones时,发现多维矩阵有一个问题需要特别注意,记录如下:

注意: 对于单通道的矩阵,所有元素为1。但是对于多维矩阵(即多通道类型),只有第一个通道的元素被设置为1,其他维度的矩阵元素全为0。

  • 函数原型
static MatExpr cv::Mat::ones	(	int 	rows,
									int 	cols,
									int 	type 
								)			

用法

  • 一维
Mat A = Mat::ones(100, 100, CV_8U)*3; // make 100x100 matrix filled with 3.
  • 多维
Mat m = Mat::ones(2, 2, CV_8UC3);
//输出结果
[1, 0, 0] [1, 0, 0]
[1, 0, 0] [1, 0, 0]

备注:

  1. 除了文中所示的函数原型,还有其他重载类型,具体用法可以查阅opencv文档。

猜你喜欢

转载自blog.csdn.net/zxcasd11/article/details/107001664
今日推荐