首页 > 代码库 > opencv-从图像旋转学习Mat数据访问

opencv-从图像旋转学习Mat数据访问

先看一个简单的例子


代码:

// ConsoleApplication3_6_23.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<opencv2/opencv.hpp>
#include<iostream>
#include<vector>
using namespace std;
using namespace cv;


int _tmain(int argc, _TCHAR* argv[])
{
	Mat src,dst,dst1,dst2;
	src = http://www.mamicode.com/imread("test.png");>

1、Mat的ptr和[]

void image_rever(Mat& src,Mat& dst)
{
	int nr = src.rows;
	int nc = src.cols;
	int ch = src.channels();
	for (int i = 0;i < nr;++i)
	{
		uchar* srcr = src.ptr<uchar>(i);
		uchar* dstr = dst.ptr<uchar>(i);
		for (int j = 0;j < nc;++j)
		{
			dstr[ch * j + 0] = srcr[ch * (nc - j - 1) + 0];
			dstr[ch * j + 1] = srcr[ch * (nc - j - 1) + 1];
			dstr[ch * j + 2] = srcr[ch * (nc - j - 1) + 2];
		}
	}
}