创建opencv Matrix时候的type

本文深入探讨了OpenCV中矩阵类型的定义、符号表示和应用实例,并通过代码示例展示了如何创建不同通道数量和数据类型的矩阵。重点介绍了如何使用CV_8UC、CV_16SC等类型创建一维、二维矩阵,以及如何利用Scalar函数初始化矩阵元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

opencv matrix type:
CV_[The number of bits per item][Signed or Unsigned][Type Prefix]C[The channel number]
CV_<bit-depth>{U|S|F}C(<number_of_channels>)

M1 with one channel =
 [255, 255;
  255, 255]

M2 with two channel =
 [0, 255, 0, 255;
  0, 255, 0, 255]

M3 with three channel =
 [0, 0, 255, 0, 0, 255;
  0, 0, 255, 0, 0, 255]


#include "opencv/cv.h"
#include <iostream>

using namespace std;
using namespace cv;

int main(char* args) {
  Mat M1(2,2, CV_8UC1, 255);
  Mat M2(2,2, CV_8UC2, Scalar(0,255));
  Mat M3(2,2, CV_8UC3, Scalar(0,0,255));

  cout << "M1 with one channel = "<< endl << " "  << M1 << endl << endl;
  cout << "M2 with two channel = "<< endl << " "  << M2 << endl << endl;
  cout << "M3 with three channel = "<< endl << " "  << M3 << endl << endl;

  M1.create(4,4, CV_8UC(2));
  cout << "M1 = "<< endl << " "  << M1 << endl << endl;

  Scalar s1(1);
  Scalar s2(1, 2);
  Scalar s3(1, 2, 3);
  Scalar s4(1, 2, 3, 4);
  Scalar s5(1, 2, 3, 5);
//  Scalar s(1, 2, 3, 5, 6, 7, 8, 9);
  cout << "scalar s1 "<< endl << " "  << s1 << endl << endl;
  cout << "scalar s2 "<< endl << " "  << s2 << endl << endl;
  cout << "scalar s3 "<< endl << " "  << s3 << endl << endl;
  cout << "scalar s4 "<< endl << " "  << s4 << endl << endl;
  cout << "scalar s5 "<< endl << " "  << s5 << endl << endl;
//  cout << "scalar s5 "<< endl << " "  << s << endl << endl;

}


http://stackoverflow.com/questions/8377091/what-are-the-differences-between-cv-8u-and-cv-32f-and-what-should-i-worry-about
http://docs.opencv.org/java/org/opencv/core/CvType.html

注释: 只有二位的matrix可以打印,多维的话,你自己需要写输出方法
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值