当前位置:网站首页>图形对象的创建与赋值
图形对象的创建与赋值
2022-07-07 10:33:00 【什么时候上岸?】
下面是示例代码:
void demo::tuxiang_creation()
{
Mat m3 = Mat::ones(Size(400, 400), CV_8UC3);
//std::cout << "width " << m3.cols << "height " << m3.rows << "channels " << m3.channels() << std::endl;
m3 = Scalar(0,255,0);
//std::cout << m3 << std::endl;
//imshow("创建图像", m3);
//Mat m4 = m3;
Mat m4;
m4=m3.clone();
m4 = Scalar(255, 0, 0);
imshow("图像", m3);
imshow("图像4", m4);
}
在opencv里面基本的计算单元是矩阵,用Mat作为前缀就可以定义矩阵了,在C++里面最重要的概念就是类的概念,我们可以把Mat看成是一个矩阵类,在类里面包含了对类的一些基本操作,而ones(图像大小,通道类型),就是这样的一个操作,它创建一个像素点为400x400,三通道的图像,把返回值赋值给m3。
std::cout << "width " << m3.cols << "height " << m3.rows << "channels " << m3.channels() << std::endl;
//输出矩阵的行长,列长,元素长度
结果如下:

给矩阵赋值,如果直接给矩阵赋值,例如m3=255,则只是给m3元素的第一个值赋值为255,元素其余部分不变,
m3 = 255;
std::cout << m3 << std::endl;
Mat m4=m3;
m4与m3共用一份数据,m4改变时,m3也同时改变,同理,m3改变,m4也会改变,像是C++里面引用的概念。
还有一点是今天才发现的,就是imshow()这个函数如果创建的窗口名字相同的话,他是只会显示一个窗口的,后一个窗口会覆盖前一个窗口。

over!!!
边栏推荐
- Idea 2021 Chinese garbled code
- Minimalist movie website
- 解密GD32 MCU产品家族,开发板该怎么选?
- [pytorch practice] image description -- let neural network read pictures and tell stories
- An error occurred when vscade tried to create a file in the target directory: access denied [resolved]
- Baidu digital person Du Xiaoxiao responded to netizens' shouts online to meet the Shanghai college entrance examination English composition
- Configure an encrypted web server
- Multi row and multi column flex layout
- 数据库系统原理与应用教程(008)—— 数据库相关概念练习题
- Cookie
猜你喜欢

Attack and defense world ----- summary of web knowledge points

静态Vxlan 配置

Static comprehensive experiment

leetcode刷题:二叉树20(二叉搜索树中的搜索)

SQL Lab (41~45) (continuous update later)

Attack and defense world - PWN learning notes

The left-hand side of an assignment expression may not be an optional property access.ts(2779)

【统计学习方法】学习笔记——支持向量机(上)

SQL lab 26~31 summary (subsequent continuous update) (including parameter pollution explanation)

IPv6 experiment
随机推荐
数据库系统原理与应用教程(010)—— 概念模型与数据模型练习题
Cryptography series: detailed explanation of online certificate status protocol OCSP
College entrance examination composition, high-frequency mention of science and Technology
Is it safe to open an account in Ping An Securities mobile bank?
Static comprehensive experiment
gcc 编译报错
Error in compiling libssl
RHSA first day operation
牛客网刷题网址
爱可可AI前沿推介(7.7)
30. Feed shot named entity recognition with self describing networks reading notes
JS to convert array to tree data
Ctfhub -web SSRF summary (excluding fastcgi and redI) super detailed
Inverted index of ES underlying principle
SQL lab 21~25 summary (subsequent continuous update) (including secondary injection explanation)
编译 libssl 报错
Apache installation problem: configure: error: APR not found Please read the documentation
Multi row and multi column flex layout
On valuation model (II): PE index II - PE band
Processing strategy of message queue message loss and repeated message sending