(计算机视觉)计算机视觉基础

7 篇文章 0 订阅
1 篇文章 0 订阅

一、常用的图像处理库

OpenCV
CxImage
CImg
FreeImage

二、开源项目

OpenBR:人脸识别相关
EasyPR:车牌识别相关

三、开发工具相关

OpenCV中VC库的版本与Visual Studio版本的对应关系:
VC8 —> 2005
VC9 —> 2008
VC10 —> 2010
VC11 —> 2012
VC12 —> 2013
VC14 —> 2015
VC15 —> 2017
Visual Studio中的辅助工具
Image Watch:C++调试时可以可视化查看内存状态的一个辅助工具。

四、Mat基础

1、常用构造函数

Mat()
Mat(int rows, int cols, int type)
Mat(Size size, int type)
Mat(int rows, int cols, int type, const Scalar& s)
Mat(Size size, int type, const Scalar& s)
Mat(const Mat& m)
Mat(int rows, int cols, int type, void* data, size_t step = AUTO_STEP)
Mat(Size size, int type, void* data, size_t step = AUTO_STEP)
Mat(const Mat& m, const Range& rowRange, const Range& colRange)
Mat(const Mat&m, const Rect& roi)  

2、OpenCV 浅拷贝与深拷贝
浅拷贝:
在 Mat 中提取 ROI 或者直接复制属于浅拷贝。
浅拷贝只拷贝矩阵头,存储数据的内存空间是共享的,在新生成的 Mat 对象中,数据指针指向被拷贝的 Mat 对象的内存地址。
深拷贝:
深拷贝不仅重新生成矩阵头(包含矩阵尺寸,存储方法,存储地址等信息),而且重新开辟了一块内存空间来存储矩阵数据,用一个指针来指向该地址。

m1.copyTo(Mat& m2)
m2 = m1.clone()  

3、生成特殊的矩阵

Mat m = Mat::zeros(int rows, int cols, int type)      //生成全0矩阵
Mat m = Mat::ones(int rows, int cols, int type)      //生成全1矩阵
Mat m = Mat::eye(int rows, int cols, int type)       //生成对角阵

4、像素值读写

  1. 通过 .at<>(i, j) 进行读写
	for (int i = 0; i < rows; ++i){
		for (int j = 0; j < cols; ++j)
		{
			grayIm.at<uchar>(i, j) = (i + j) % 255;       // 读取灰度图
			Vec3b pixel;
			pixel = colorIm.at<Vec3b>(i, j);                // 读取彩色图
		}
	}
  1. 通过迭代器进行读写
Mat Iterator_<uchar> grayIt, grayEnd;     // 如果是彩色图,只需要将 uchar 改为 Vec3b
for (grayIt = grayIm.begin<uchar>(), grayEnd = grayIm.end<uchar>(); 
	  grayIt != grayIm; ++grayIt){
	*grayIt = 0;
}
  1. 通过指针进行读写
    Mat 中有一个 *data 指针,指向存储的数据的首地址。
for (int i = 0; i < rows; ++i){
	uchar* p = grayIm.ptr<uchar>(i);       // 获取第i行的首地址
	for (int j = 0; j < cols; ++j)       
		*(p++) = j;
}
  1. 使用 step 的方式进行读写
    在这里插入图片描述
  2. 使用 Mat_ 类
    Mat_ 类是对 Mat 类的一个包装,定义如下:
template<typename _Tp> 
class Mat_ : public Mat
{
	public:
		// 只定义了几个方法
		// 没有定义新的属性
}

使用 Mat_ 类之后可以直接使用元素的下标进行读写:

Mat_<uchar> M1 = (Mat_<uchar> &)M;
for (int i = 0; i < M1.rows; ++i){
	*p = M1.ptr(i);
	for (int j = 0; j < cols; ++j)
		M1(i, j) = 1;
}

五、推荐资料

手册:http://docs.opencv.org/
教程:http://docs.opencv.org/doc/tutorials/tutorials.html
进阶:http://github.com/opencv/opencv/wiki

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值