OpenCV2.x 学习笔记02--遍历像素点操作

目录

Mat简介

IplImage简介

功能函数参考程序代码


TIme:20180905

ENV:Vs2013、OPencv2.4.9

Function:二维图像数据转存一维数组算法实现

Athor:New

Mat简介

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);
......
}

IplImage简介

IplImage*是C语言操作OpenCV1.x的数据结构,在当时C操纵opencv的时候,地位等同于Mat,OpenCV为其提供了一个接口,很方便的直接将IplImage转化为Mat,即使用构造函数 

Mat(const IplImage* img, bool copyData=false);

功能函数参考程序代码

//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.youkuaiyun.com/xiahouzuoxin/article/details/38298165

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值