当前位置:网站首页>图形对象的创建与赋值
图形对象的创建与赋值
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!!!
边栏推荐
- Solutions to cross domain problems
- GCC compilation error
- Attack and defense world ----- summary of web knowledge points
- leetcode刷题:二叉树26(二叉搜索树中的插入操作)
- Will the filing free server affect the ranking and weight of the website?
- 什么是ESP/MSR 分区,如何建立ESP/MSR 分区
- (to be deleted later) yyds, paid academic resources, please keep a low profile!
- BGP third experiment report
- Simple network configuration for equipment management
- 编译 libssl 报错
猜你喜欢

Xiaohongshu microservice framework and governance and other cloud native business architecture evolution cases

【统计学习方法】学习笔记——逻辑斯谛回归和最大熵模型

(待会删)yyds,付费搞来的学术资源,请低调使用!

数据库系统原理与应用教程(010)—— 概念模型与数据模型练习题

Solve server returns invalid timezone Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually

解决 Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually

Hi3516 full system type burning tutorial

Tutorial on principles and applications of database system (007) -- related concepts of database

数据库系统原理与应用教程(007)—— 数据库相关概念

Inverted index of ES underlying principle
随机推荐
解密GD32 MCU产品家族,开发板该怎么选?
静态Vxlan 配置
Customize the web service configuration file
[statistical learning methods] learning notes - Chapter 5: Decision Tree
牛客网刷题网址
《看完就懂系列》天哪!搞懂节流与防抖竟简单如斯~
跨域问题解决方案
解决 Server returns invalid timezone. Go to ‘Advanced’ tab and set ‘serverTimezone’ property manually
SQL Lab (36~40) includes stack injection, MySQL_ real_ escape_ The difference between string and addslashes (continuous update after)
"Series after reading" my God! It's so simple to understand throttling and anti shake~
leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)
The hoisting of the upper cylinder of the steel containment of the world's first reactor "linglong-1" reactor building was successful
【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
2022聚合工艺考试题模拟考试题库及在线模拟考试
leetcode刷题:二叉树20(二叉搜索树中的搜索)
Static routing assignment of network reachable and telent connections
wallys/Qualcomm IPQ8072A networking SBC supports dual 10GbE, WiFi 6
Using stack to convert binary to decimal
SQL Lab (46~53) (continuous update later) order by injection
(待会删)yyds,付费搞来的学术资源,请低调使用!