一、常用的图像处理库
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、像素值读写
- 通过 .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); // 读取彩色图
}
}
- 通过迭代器进行读写
Mat Iterator_<uchar> grayIt, grayEnd; // 如果是彩色图,只需要将 uchar 改为 Vec3b
for (grayIt = grayIm.begin<uchar>(), grayEnd = grayIm.end<uchar>();
grayIt != grayIm; ++grayIt){
*grayIt = 0;
}
- 通过指针进行读写
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;
}
- 使用 step 的方式进行读写
- 使用 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