TIme:20180905
ENV:Vs2013、OPencv2.4.9
Function:二维图像数据转存一维数组算法实现
Athor:New(XATU)
------------------------------
1、Mat简介
2、IplImage简介
3、功能函数参考i程序代码
-------------------------------------------
1、Mat是OpenCV最基本的数据结构,Mat即矩阵(Matrix)的缩写,Mat数据结构主要包含2部分:Header和Pointer。Header中主要包含矩阵的大小,存储方式,存储地址等信息;Pointer中存储指向像素值的指针。我们在读取图片的时候就是将图片定义为Mat类型,其重载的构造函数一大堆,
-
- classCV_EXPORTSMat
- {
- public:
- //! default constructor
- Mat();
- //! constructs 2D matrix of the specified size and type
- // (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
- Mat(int _rows, int _cols, int _type);
- Mat(Size _size, int _type);
- //! constucts 2D matrix and fills it with the specified value _s.
- Mat(int _rows, int _cols, int _type, const Scalar& _s);
- Mat(Size _size, int _type, const Scalar& _s);
- //! constructs n-dimensional matrix
- Mat(int _ndims, constint* _sizes, int _type);
- Mat(int _ndims, constint* _sizes, int _type, const Scalar& _s);
- //! copy constructor
- Mat(const Mat& m);
- //! constructor for matrix headers pointing to user-allocated data
- 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(int _ndims, constint* _sizes, int _type, void* _data, constsize_t* _steps=0);
- //! creates a matrix header for a part of the bigger matrix
- Mat(const Mat& m, const Range& rowRange, const Range& colRange=Range::all());
- Mat(const Mat& m, const Rect& roi);
- Mat(const Mat& m, const Range* ranges);
- //! converts old-style CvMat to the new matrix; the data is not copied by default
- Mat(const CvMat* m, bool copyData=false);
- //! converts old-style CvMatND to the new matrix; the data is not copied by default
- Mat(const CvMatND* m, bool copyData=false);
- //! converts old-style IplImage to the new matrix; the data is not copied by default
- Mat(const IplImage* img, bool copyData=false);
- ......
- }
2、IplImage*是C语言操作OpenCV1.x的数据结构,在当时C操纵opencv的时候,地位等同于Mat,OpenCV为其提供了一个接口,很方便的直接将IplImage转化为Mat,即使用构造函数
Mat(const IplImage* img, bool copyData=false);
3、功能函数参考i程序代码
//Info:Mainsfs01.cpp
//变量为初始化
//Get_UCF_Image_Format(),二维图像数据转存一维数组算法实现-。
//程序规范化
//Env:VS2013、Opencv2.4.9
//Function:
//Time:20180831
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include "ImageTools.h"
using namespace std;
using namespace cv;
#define SSize 200
void Get_UCF_Image_Format(Mat s, uchar* d)
{
int i, j;
int width;// widthStep;
int height;
//width = s->width;/* 图像宽像素数 */
//height = s->height;
width = s.cols;//列长
height = s.rows;//行
//用指针访问像素,速度最快
uchar *p;
for (int i = 0; i < height; i++)
{
p = s.ptr<uchar>(i);//获取每行首地址
for (int j = 0; j < width; j++)
{
d[i*height + j] = p[j];
}
}
}
有疑问欢迎留言,不定期查看
其他参考:https://blog.csdn.net/xiahouzuoxin/article/details/38298165