Opencv官网手册学习---1
来源:互联网 发布:淘宝助理一键放入仓库 编辑:程序博客网 时间:2024/06/10 23:15
Opencv学习系列是针对opencv官网的tutorials进行学习之后,然后再整理,记录。
方便以后学习使用。以后的文章不再声明
Mat is basically a class with two data parts: the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for storing) . The matrix header size is constant。
图像的拷贝有很多种,先介绍本文中提到的,之后的遇见在说:
括号复制:这种方式只会拷贝图像头结点。
比如
Mat A=imread("lena.jpa",1);Mat B(A);
以上方式在不用的时候不会自动清空内存
那么如果需要一种不需要时自动清空的拷贝怎么办?
Opencv提供了两个函数:
cv::Mat::clone() 和 cv::Mat::copyTo() functions.
Mat A=imread("lena.jpa",1);Mat B=A.clone();Mat C;A.copyTo(C);
附上代码:
#include"opencv2/opencv.hpp"#include <iostream>using namespace cv;using namespace std;int main(){ Mat A = imread("C:\\Users\\asus\\Desktop\\lena.jpg", 1);//1是默认读入 imshow("origin", A); Mat B(A); imshow("1", B); Mat C(A, Rect(180, 200, 200, 200));//ROI imshow("2", C); Mat D; A.copyTo(D); imshow("3", D); waitKey(0); return 0;}
下面记录一下Mat的构造方法:
cv::Mat::Mat Constructor
Mat M(2,2, CV_8UC3, Scalar(0,0,255)); cout << "M = " << endl << " " << M << endl << endl;
两行很好理解,但是为什么这里有6行呢?
这是因为我们创建的是3个通道的,每一列有3个通道,所以就有6列了
M对象前两个参数是矩阵的行列数,第三个参数是数据类型:
CV_[The number of bits per item][Signed or Unsigned][Type Prefix]C[The channel number]
所以CV_8UC3意思是:8位无符号char型的,并且每个像素有3个通道。也就是RGB。相应的有CV_8UC1,CV_8UC2。
cv::Scalar是用来初始化的,将矩阵设置为单一灰度。
如果是(255,0,0),则图像是全蓝
如果是(0,255,0),图像是全绿
如果是(0,0,255),图像是全红
cv::Mat::create()函数也可以创建
M.create(4,4, CV_8UC(2)); cout << "M = "<< endl << " " << M << endl << endl;
介绍几个MATLAB常用的初始化函数,全0,全1,和单位矩阵
Mat E = Mat::eye(4, 4, CV_64F);
cout << “E = ” << endl << ” ” << E << endl << endl;
Mat O = Mat::ones(2, 2, CV_32F);
cout << “O = ” << endl << ” ” << O << endl << endl;
Mat Z = Mat::zeros(3,3, CV_8UC1);
cout << “Z = ” << endl << ” ” << Z << endl << endl;
CV_64F代表64为浮点型数据
对于小矩阵,也可以进行手动初始化
Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0); cout << "C = " << endl << " " << C << endl << endl;
- Opencv官网手册学习---1
- opencv 学习手册
- 《Opencv 2计算机视觉编程手册 》学习笔记 1
- OpenCV API应用手册(1)- OpenCV各个功能模块介绍
- JBPM学习手册(1)
- Enterprise4.1 学习手册
- Android 学习 手册(1)
- 计算机系统 学习手册 1
- Opencv学习手册(一)--- 图像文件读入和显示
- Opencv学习手册(二)--- 图像采集与显示
- Opencv学习手册(三)---图像坐标变换
- Opencv学习手册(四)--- 图像灰度变换
- opencv中文手册
- XML 轻松学习手册[1]
- Emacs 中文学习手册-1
- 《python学习手册》(1)
- python学习手册总结1
- python学习手册(1)
- FZU
- (转)C++指针问题
- 44:第n小的质数
- Centos-7 + Docker-1.12 中 devicemapper + direct_lvm 的 Docker 存储配置
- GreenDao的简单使用
- Opencv官网手册学习---1
- Error:Invalid command android
- nodejs 和 npm安装配置与常见问题
- Analysis of Computational Complexity and Space Complexity (NN algorithem)
- 最简单清晰的纯css实现的单选框radio复选框checkbox自定义样式
- hdu6154-CaoHaha's staff(找规律)
- Spring Controller 获取请求参数的几种方法
- HTTP状态码详解
- C. Inna and Dima----dfs