当前位置:网站首页>图形对象的创建与赋值
图形对象的创建与赋值
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!!!
边栏推荐
- Tutorial on the principle and application of database system (008) -- exercises on database related concepts
- BGP actual network configuration
- Static vxlan configuration
- The IDM server response shows that you do not have permission to download the solution tutorial
- Tutorial on the principle and application of database system (011) -- relational database
- Static comprehensive experiment
- MPLS experiment
- Minimalist movie website
- Epp+dis learning path (1) -- Hello world!
- leetcode刷题:二叉树19(合并二叉树)
猜你喜欢

H3C HCl MPLS layer 2 dedicated line experiment

2022A特种设备相关管理(锅炉压力容器压力管道)模拟考试题库模拟考试平台操作

Tutorial on the principle and application of database system (011) -- relational database

Attack and defense world - PWN learning notes

SQL Lab (46~53) (continuous update later) order by injection

数据库系统原理与应用教程(011)—— 关系数据库

What is an esp/msr partition and how to create an esp/msr partition

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

JS to convert array to tree data

About web content security policy directive some test cases specified through meta elements
随机推荐
Tutorial on the principle and application of database system (008) -- exercises on database related concepts
About sqli lab less-15 using or instead of and parsing
Solutions to cross domain problems
leetcode刷题:二叉树25(二叉搜索树的最近公共祖先)
Minimalist movie website
Idea 2021 Chinese garbled code
利用栈来实现二进制转化为十进制
Learning and using vscode
数据库安全的重要性
30. Feed shot named entity recognition with self describing networks reading notes
How much does it cost to develop a small program mall?
(to be deleted later) yyds, paid academic resources, please keep a low profile!
OSPF exercise Report
开发一个小程序商城需要多少钱?
Realize all, race, allsettled and any of the simple version of promise by yourself
[Q&A]AttributeError: module ‘signal‘ has no attribute ‘SIGALRM‘
【统计学习方法】学习笔记——第四章:朴素贝叶斯法
File upload vulnerability - upload labs (1~2)
【PyTorch实战】用PyTorch实现基于神经网络的图像风格迁移
普乐蛙小型5d电影设备|5d电影动感电影体验馆|VR景区影院设备