阅读背景:

【VC图像处理】 图像水平镜像,垂直镜像,图像转置

来源:互联网 
#include "opencv2/core/core.hpp"
#include"opencv2/highgui/highgui.hpp"
#include<opencv2/opencv.hpp>
#include "iostream"
using namespace std;
using namespace cv;

void OnMirror_X(Mat img,Mat &OutImg)
{
	int Width=img.cols;
	int Height=img.rows;
	OutImg.create(Height,Width,img.type());

	for(int i=0;i<Height;i++)
		for(int j=0;j<Width/2;j++)
		{
			if(img.channels()==1)
			{

				OutImg.at<uchar>(i,j)=img.at<uchar>(i,Width-j-1);
				OutImg.at<uchar>(i,(Width-j-1))=img.at<uchar>(i,j);
			}
			else if(img.channels()==3)
			{
				OutImg.at<Vec3b>(i,j)=img.at<Vec3b>(i,Width-j-1);
				OutImg.at<Vec3b>(i,Width-j-1)=img.at<Vec3b>(i,j);
			}
		}
}

void OnMirror_Y(Mat img,Mat &OutImg)
{

	int Width=img.cols;
	int Height=img.rows;
	OutImg.create(Height,Width,img.type());
	for(int i=0;i<Height/2;i++)
		for(int j=0;j<Width;j++)
		{
			if(img.channels()==1)
			{
				OutImg.at<uchar>(i,j)=img.at<uchar>(Height-i-1,j);  //一开始没加-1  内存老报错!!!~~~  细心啊
				OutImg.at<uchar>(Height-i-1,j)=img.at<uchar>(i,j);

			}
			else if(img.channels()==3)
			{
				OutImg.at<Vec3b>(i,j)=img.at<Vec3b>(Height-i-1,j);
				OutImg.at<Vec3b>(Height-i-1,j)=img.at<Vec3b>(i,j);
			}
		}}#include "opencv2/core/core.hpp"
#include"openc



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: